Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Mr、小李
TDengine
提交
a797219b
T
TDengine
项目概览
Mr、小李
/
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
a797219b
编写于
11月 21, 2019
作者:
H
hjxilinx
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[tbase-1210]
上级
7a517945
变更
9
展开全部
隐藏空白更改
内联
并排
Showing
9 changed file
with
581 addition
and
390 deletion
+581
-390
src/client/inc/tscUtil.h
src/client/inc/tscUtil.h
+4
-2
src/client/inc/tsclient.h
src/client/inc/tsclient.h
+6
-1
src/client/src/tscLocal.c
src/client/src/tscLocal.c
+85
-15
src/client/src/tscSQLParser.c
src/client/src/tscSQLParser.c
+76
-10
src/client/src/tscSQLParserImpl.c
src/client/src/tscSQLParserImpl.c
+16
-6
src/client/src/tscServer.c
src/client/src/tscServer.c
+7
-0
src/client/src/tscUtil.c
src/client/src/tscUtil.c
+15
-2
src/inc/sql.y
src/inc/sql.y
+10
-2
src/util/src/sql.c
src/util/src/sql.c
+362
-352
未找到文件。
src/client/inc/tscUtil.h
浏览文件 @
a797219b
...
...
@@ -127,7 +127,7 @@ int tscAllocPayload(SSqlCmd* pCmd, int size);
void
tscFieldInfoSetValFromSchema
(
SFieldInfo
*
pFieldInfo
,
int32_t
index
,
SSchema
*
pSchema
);
void
tscFieldInfoSetValFromField
(
SFieldInfo
*
pFieldInfo
,
int32_t
index
,
TAOS_FIELD
*
pField
);
void
tscFieldInfoSetValue
(
SFieldInfo
*
pFieldInfo
,
int32_t
index
,
int8_t
type
,
char
*
name
,
int16_t
bytes
);
void
tscFieldInfoSetValue
(
SFieldInfo
*
pFieldInfo
,
int32_t
index
,
int8_t
type
,
c
onst
c
har
*
name
,
int16_t
bytes
);
void
tscFieldInfoUpdateVisible
(
SFieldInfo
*
pFieldInfo
,
int32_t
index
,
bool
visible
);
void
tscFieldInfoCalOffset
(
SSqlCmd
*
pCmd
);
...
...
@@ -143,7 +143,9 @@ void tscClearFieldInfo(SFieldInfo* pFieldInfo);
void
addExprParams
(
SSqlExpr
*
pExpr
,
char
*
argument
,
int32_t
type
,
int32_t
bytes
,
int16_t
tableIndex
);
SSqlExpr
*
tscSqlExprInsert
(
SSqlCmd
*
pCmd
,
int32_t
index
,
int16_t
functionId
,
SColumnIndex
*
pColIndex
,
int16_t
type
,
int16_t
size
,
/*int16_t colId,*/
int16_t
interSize
);
int16_t
size
,
int16_t
interSize
);
SSqlExpr
*
tscSqlExprInsertEmpty
(
SSqlCmd
*
pCmd
,
int32_t
index
,
int16_t
functionId
);
SSqlExpr
*
tscSqlExprUpdate
(
SSqlCmd
*
pCmd
,
int32_t
index
,
int16_t
functionId
,
int16_t
srcColumnIndex
,
int16_t
type
,
int16_t
size
);
...
...
src/client/inc/tsclient.h
浏览文件 @
a797219b
...
...
@@ -92,7 +92,12 @@ enum _sql_cmd {
*/
TSDB_SQL_RETRIEVE_EMPTY_RESULT
,
TSDB_SQL_RESET_CACHE
,
TSDB_SQL_RESET_CACHE
,
// 40
TSDB_SQL_SERV_STATUS
,
TSDB_SQL_CURRENT_DB
,
TSDB_SQL_SERV_VERSION
,
TSDB_SQL_CLI_VERSION
,
TSDB_SQL_CURRENT_USER
,
TSDB_SQL_CFG_LOCAL
,
TSDB_SQL_MAX
...
...
src/client/src/tscLocal.c
浏览文件 @
a797219b
...
...
@@ -26,6 +26,8 @@
#include "tschemautil.h"
#include "tsocket.h"
static
void
tscSetLocalQueryResult
(
SSqlObj
*
pSql
,
const
char
*
val
,
const
char
*
columnName
,
size_t
valueLength
);
static
int32_t
getToStringLength
(
const
char
*
pData
,
int32_t
length
,
int32_t
type
)
{
char
buf
[
512
]
=
{
0
};
...
...
@@ -39,7 +41,7 @@ static int32_t getToStringLength(const char *pData, int32_t length, int32_t type
case
TSDB_DATA_TYPE_DOUBLE
:
{
#ifdef _TD_ARM_32_
double
dv
=
0
;
*
(
int64_t
*
)(
&
dv
)
=
*
(
int64_t
*
)
pData
;
*
(
int64_t
*
)(
&
dv
)
=
*
(
int64_t
*
)
pData
;
len
=
sprintf
(
buf
,
"%f"
,
dv
);
#else
len
=
sprintf
(
buf
,
"%lf"
,
*
(
double
*
)
pData
);
...
...
@@ -47,12 +49,11 @@ static int32_t getToStringLength(const char *pData, int32_t length, int32_t type
if
(
strncasecmp
(
"nan"
,
buf
,
3
)
==
0
)
{
len
=
4
;
}
}
break
;
}
break
;
case
TSDB_DATA_TYPE_FLOAT
:
{
#ifdef _TD_ARM_32_
float
fv
=
0
;
*
(
int32_t
*
)(
&
fv
)
=
*
(
int32_t
*
)
pData
;
*
(
int32_t
*
)(
&
fv
)
=
*
(
int32_t
*
)
pData
;
len
=
sprintf
(
buf
,
"%f"
,
fv
);
#else
len
=
sprintf
(
buf
,
"%f"
,
*
(
float
*
)
pData
);
...
...
@@ -60,8 +61,7 @@ static int32_t getToStringLength(const char *pData, int32_t length, int32_t type
if
(
strncasecmp
(
"nan"
,
buf
,
3
)
==
0
)
{
len
=
4
;
}
}
break
;
}
break
;
case
TSDB_DATA_TYPE_TIMESTAMP
:
case
TSDB_DATA_TYPE_BIGINT
:
len
=
sprintf
(
buf
,
"%lld"
,
*
(
int64_t
*
)
pData
);
...
...
@@ -203,23 +203,21 @@ static int32_t tscSetValueToResObj(SSqlObj *pSql, int32_t rowLen) {
case
TSDB_DATA_TYPE_FLOAT
:
{
#ifdef _TD_ARM_32_
float
fv
=
0
;
*
(
int32_t
*
)(
&
fv
)
=
*
(
int32_t
*
)
pTagValue
;
*
(
int32_t
*
)(
&
fv
)
=
*
(
int32_t
*
)
pTagValue
;
sprintf
(
target
,
"%f"
,
fv
);
#else
sprintf
(
target
,
"%f"
,
*
(
float
*
)
pTagValue
);
#endif
}
break
;
}
break
;
case
TSDB_DATA_TYPE_DOUBLE
:
{
#ifdef _TD_ARM_32_
double
dv
=
0
;
*
(
int64_t
*
)(
&
dv
)
=
*
(
int64_t
*
)
pTagValue
;
*
(
int64_t
*
)(
&
dv
)
=
*
(
int64_t
*
)
pTagValue
;
sprintf
(
target
,
"%lf"
,
dv
);
#else
sprintf
(
target
,
"%lf"
,
*
(
double
*
)
pTagValue
);
#endif
}
break
;
}
break
;
case
TSDB_DATA_TYPE_TINYINT
:
sprintf
(
target
,
"%d"
,
*
(
int8_t
*
)
pTagValue
);
break
;
...
...
@@ -391,6 +389,68 @@ static int tscProcessQueryTags(SSqlObj *pSql) {
}
}
static
void
tscProcessCurrentUser
(
SSqlObj
*
pSql
)
{
SSqlExpr
*
pExpr
=
tscSqlExprGet
(
&
pSql
->
cmd
,
0
);
tscSetLocalQueryResult
(
pSql
,
pSql
->
pTscObj
->
user
,
pExpr
->
aliasName
,
TSDB_USER_LEN
);
}
static
void
tscProcessCurrentDB
(
SSqlObj
*
pSql
)
{
char
db
[
TSDB_DB_NAME_LEN
+
1
]
=
{
0
};
extractDBName
(
pSql
->
pTscObj
->
db
,
db
);
// no use db is invoked before.
if
(
strlen
(
db
)
==
0
)
{
setNull
(
db
,
TSDB_DATA_TYPE_BINARY
,
TSDB_DB_NAME_LEN
);
}
SSqlExpr
*
pExpr
=
tscSqlExprGet
(
&
pSql
->
cmd
,
0
);
tscSetLocalQueryResult
(
pSql
,
db
,
pExpr
->
aliasName
,
TSDB_DB_NAME_LEN
);
}
static
void
tscProcessServerVer
(
SSqlObj
*
pSql
)
{
const
char
*
v
=
pSql
->
pTscObj
->
sversion
;
SSqlExpr
*
pExpr
=
tscSqlExprGet
(
&
pSql
->
cmd
,
0
);
tscSetLocalQueryResult
(
pSql
,
v
,
pExpr
->
aliasName
,
tListLen
(
pSql
->
pTscObj
->
sversion
));
}
static
void
tscProcessClientVer
(
SSqlObj
*
pSql
)
{
SSqlExpr
*
pExpr
=
tscSqlExprGet
(
&
pSql
->
cmd
,
0
);
tscSetLocalQueryResult
(
pSql
,
version
,
pExpr
->
aliasName
,
strlen
(
version
));
}
static
void
tscProcessServStatus
(
SSqlObj
*
pSql
)
{
STscObj
*
pObj
=
pSql
->
pTscObj
;
if
(
pObj
->
pHb
!=
NULL
)
{
if
(
pObj
->
pHb
->
res
.
code
==
TSDB_CODE_NETWORK_UNAVAIL
)
{
pSql
->
res
.
code
=
TSDB_CODE_NETWORK_UNAVAIL
;
return
;
}
}
else
{
if
(
pSql
->
res
.
code
==
TSDB_CODE_NETWORK_UNAVAIL
)
{
return
;
}
}
SSqlExpr
*
pExpr
=
tscSqlExprGet
(
&
pSql
->
cmd
,
0
);
tscSetLocalQueryResult
(
pSql
,
"1"
,
pExpr
->
aliasName
,
2
);
}
void
tscSetLocalQueryResult
(
SSqlObj
*
pSql
,
const
char
*
val
,
const
char
*
columnName
,
size_t
valueLength
)
{
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SSqlRes
*
pRes
=
&
pSql
->
res
;
pCmd
->
numOfCols
=
1
;
pCmd
->
order
.
order
=
TSQL_SO_ASC
;
tscFieldInfoSetValue
(
&
pCmd
->
fieldsInfo
,
0
,
TSDB_DATA_TYPE_BINARY
,
columnName
,
valueLength
);
tscInitResObjForLocalQuery
(
pSql
,
1
,
valueLength
);
TAOS_FIELD
*
pField
=
tscFieldInfoGetField
(
pCmd
,
0
);
strncpy
(
pRes
->
data
,
val
,
pField
->
bytes
);
}
int
tscProcessLocalCmd
(
SSqlObj
*
pSql
)
{
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
...
...
@@ -402,13 +462,23 @@ int tscProcessLocalCmd(SSqlObj *pSql) {
pSql
->
res
.
code
=
(
uint8_t
)
tscProcessQueryTags
(
pSql
);
}
else
if
(
pCmd
->
command
==
TSDB_SQL_RETRIEVE_EMPTY_RESULT
)
{
/*
*
pass the qhandle check, in order
to call partial release function to
* free allocated resources and remove the SqlObj from linked list
*
set the qhandle to be 1 in order to pass the qhandle check, and
to call partial release function to
* free allocated resources and remove the SqlObj from
sql query
linked list
*/
pSql
->
res
.
qhandle
=
0x1
;
// pass the qhandle check
pSql
->
res
.
qhandle
=
0x1
;
pSql
->
res
.
numOfRows
=
0
;
}
else
if
(
pCmd
->
command
==
TSDB_SQL_RESET_CACHE
)
{
taosClearDataCache
(
tscCacheHandle
);
}
else
if
(
pCmd
->
command
==
TSDB_SQL_SERV_VERSION
)
{
tscProcessServerVer
(
pSql
);
}
else
if
(
pCmd
->
command
==
TSDB_SQL_CLI_VERSION
)
{
tscProcessClientVer
(
pSql
);
}
else
if
(
pCmd
->
command
==
TSDB_SQL_CURRENT_USER
)
{
tscProcessCurrentUser
(
pSql
);
}
else
if
(
pCmd
->
command
==
TSDB_SQL_CURRENT_DB
)
{
tscProcessCurrentDB
(
pSql
);
}
else
if
(
pCmd
->
command
==
TSDB_SQL_SERV_STATUS
)
{
tscProcessServStatus
(
pSql
);
}
else
{
pSql
->
res
.
code
=
TSDB_CODE_INVALID_SQL
;
tscError
(
"%p not support command:%d"
,
pSql
,
pCmd
->
command
);
...
...
src/client/src/tscSQLParser.c
浏览文件 @
a797219b
...
...
@@ -117,7 +117,8 @@ static int32_t optrToString(tSQLExpr* pExpr, char** exprString);
static
SColumnList
getColumnList
(
int32_t
num
,
int16_t
tableIndex
,
int32_t
columnIndex
);
static
int32_t
getMeterIndex
(
SSQLToken
*
pTableToken
,
SSqlCmd
*
pCmd
,
SColumnIndex
*
pIndex
);
static
int32_t
doFunctionsCompatibleCheck
(
SSqlObj
*
pSql
);
static
int32_t
doLocalQueryProcess
(
SQuerySQL
*
pQuerySql
,
SSqlCmd
*
pCmd
);
static
int32_t
tscQueryOnlyMetricTags
(
SSqlCmd
*
pCmd
,
bool
*
queryOnMetricTags
)
{
assert
(
QUERY_IS_STABLE_QUERY
(
pCmd
->
type
));
...
...
@@ -877,7 +878,7 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
case
TSQL_QUERY_METER
:
{
SQuerySQL
*
pQuerySql
=
pInfo
->
pQueryInfo
;
assert
(
pQuerySql
!=
NULL
&&
pQuerySql
->
from
->
nExpr
>
0
);
assert
(
pQuerySql
!=
NULL
&&
(
pQuerySql
->
from
==
NULL
||
pQuerySql
->
from
->
nExpr
>
0
)
);
const
char
*
msg0
=
"invalid table name"
;
const
char
*
msg1
=
"table name too long"
;
...
...
@@ -895,6 +896,19 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
setErrMsg
(
pCmd
,
msg8
);
return
TSDB_CODE_INVALID_SQL
;
}
/*
* handle the sql expression without from subclause
* select current_database();
* select server_version();
* select client_version();
* select server_state();
*/
if
(
pQuerySql
->
from
==
NULL
)
{
assert
(
pQuerySql
->
fillType
==
NULL
&&
pQuerySql
->
pGroupby
==
NULL
&&
pQuerySql
->
pWhere
==
NULL
&&
pQuerySql
->
pSortOrder
==
NULL
);
return
doLocalQueryProcess
(
pQuerySql
,
pCmd
);
}
if
(
pQuerySql
->
from
->
nExpr
>
TSDB_MAX_JOIN_TABLE_NUM
)
{
setErrMsg
(
pCmd
,
msg7
);
...
...
@@ -1120,7 +1134,7 @@ int32_t parseIntervalClause(SSqlCmd* pCmd, SQuerySQL* pQuerySql) {
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
pCmd
,
0
);
if
(
pQuerySql
->
interval
.
type
==
0
)
{
if
(
pQuerySql
->
interval
.
type
==
0
||
pQuerySql
->
interval
.
n
==
0
)
{
return
TSDB_CODE_SUCCESS
;
}
...
...
@@ -4971,8 +4985,8 @@ int32_t validateFunctionsInIntervalOrGroupbyQuery(SSqlCmd* pCmd) {
}
typedef
struct
SDNodeDynConfOption
{
char
*
name
;
int32_t
len
;
char
*
name
;
// command name
int32_t
len
;
// name string length
}
SDNodeDynConfOption
;
int32_t
validateDNodeConfig
(
tDCLSQL
*
pOptions
)
{
...
...
@@ -4980,7 +4994,7 @@ int32_t validateDNodeConfig(tDCLSQL* pOptions) {
return
TSDB_CODE_INVALID_SQL
;
}
SDNodeDynConfOption
DNODE_DYNAMIC_CFG_OPTIONS
[
14
]
=
{
const
SDNodeDynConfOption
DNODE_DYNAMIC_CFG_OPTIONS
[
14
]
=
{
{
"resetLog"
,
8
},
{
"resetQueryCache"
,
15
},
{
"dDebugFlag"
,
10
},
{
"rpcDebugFlag"
,
12
},
{
"tmrDebugFlag"
,
12
},
{
"cDebugFlag"
,
10
},
{
"uDebugFlag"
,
10
},
{
"mDebugFlag"
,
10
},
{
"sdbDebugFlag"
,
12
},
{
"httpDebugFlag"
,
13
},
{
"monitorDebugFlag"
,
16
},
{
"qDebugflag"
,
10
},
...
...
@@ -4991,7 +5005,7 @@ int32_t validateDNodeConfig(tDCLSQL* pOptions) {
if
(
pOptions
->
nTokens
==
2
)
{
// reset log and reset query cache does not need value
for
(
int32_t
i
=
0
;
i
<
2
;
++
i
)
{
SDNodeDynConfOption
*
pOption
=
&
DNODE_DYNAMIC_CFG_OPTIONS
[
i
];
const
SDNodeDynConfOption
*
pOption
=
&
DNODE_DYNAMIC_CFG_OPTIONS
[
i
];
if
((
strncasecmp
(
pOption
->
name
,
pOptionToken
->
z
,
pOptionToken
->
n
)
==
0
)
&&
(
pOption
->
len
==
pOptionToken
->
n
))
{
return
TSDB_CODE_SUCCESS
;
}
...
...
@@ -5014,7 +5028,7 @@ int32_t validateDNodeConfig(tDCLSQL* pOptions) {
}
for
(
int32_t
i
=
2
;
i
<
tListLen
(
DNODE_DYNAMIC_CFG_OPTIONS
)
-
1
;
++
i
)
{
SDNodeDynConfOption
*
pOption
=
&
DNODE_DYNAMIC_CFG_OPTIONS
[
i
];
const
SDNodeDynConfOption
*
pOption
=
&
DNODE_DYNAMIC_CFG_OPTIONS
[
i
];
if
((
strncasecmp
(
pOption
->
name
,
pOptionToken
->
z
,
pOptionToken
->
n
)
==
0
)
&&
(
pOption
->
len
==
pOptionToken
->
n
))
{
/* options is valid */
...
...
@@ -5031,8 +5045,10 @@ int32_t validateLocalConfig(tDCLSQL* pOptions) {
return
TSDB_CODE_INVALID_SQL
;
}
SDNodeDynConfOption
LOCAL_DYNAMIC_CFG_OPTIONS
[
6
]
=
{{
"resetLog"
,
8
},
{
"rpcDebugFlag"
,
12
},
{
"tmrDebugFlag"
,
12
},
{
"cDebugFlag"
,
10
},
{
"uDebugFlag"
,
10
},
{
"debugFlag"
,
9
}};
SDNodeDynConfOption
LOCAL_DYNAMIC_CFG_OPTIONS
[
6
]
=
{
{
"resetLog"
,
8
},
{
"rpcDebugFlag"
,
12
},
{
"tmrDebugFlag"
,
12
},
{
"cDebugFlag"
,
10
},
{
"uDebugFlag"
,
10
},
{
"debugFlag"
,
9
}
};
SSQLToken
*
pOptionToken
=
&
pOptions
->
a
[
0
];
...
...
@@ -5686,3 +5702,53 @@ int32_t doFunctionsCompatibleCheck(SSqlObj* pSql) {
return
checkUpdateTagPrjFunctions
(
pCmd
);
}
}
int32_t
doLocalQueryProcess
(
SQuerySQL
*
pQuerySql
,
SSqlCmd
*
pCmd
)
{
const
char
*
msg1
=
"only one expression allowed"
;
const
char
*
msg2
=
"invalid expression in select clause"
;
const
char
*
msg3
=
"invalid function"
;
tSQLExprList
*
pExprList
=
pQuerySql
->
pSelection
;
if
(
pExprList
->
nExpr
!=
1
)
{
setErrMsg
(
pCmd
,
msg1
);
return
TSDB_CODE_INVALID_SQL
;
}
tSQLExpr
*
pExpr
=
pExprList
->
a
[
0
].
pNode
;
if
(
pExpr
->
operand
.
z
==
NULL
)
{
setErrMsg
(
pCmd
,
msg2
);
return
TSDB_CODE_INVALID_SQL
;
}
SDNodeDynConfOption
functionsInfo
[
5
]
=
{
{
"database()"
,
10
},
{
"server_version()"
,
16
},
{
"server_status()"
,
15
},
{
"client_version()"
,
16
},
{
"current_user()"
,
14
}
};
int32_t
index
=
-
1
;
for
(
int32_t
i
=
0
;
i
<
tListLen
(
functionsInfo
);
++
i
)
{
if
(
strncasecmp
(
functionsInfo
[
i
].
name
,
pExpr
->
operand
.
z
,
functionsInfo
[
i
].
len
)
==
0
&&
functionsInfo
[
i
].
len
==
pExpr
->
operand
.
n
)
{
index
=
i
;
break
;
}
}
SSqlExpr
*
pExpr1
=
tscSqlExprInsertEmpty
(
pCmd
,
0
,
TSDB_FUNC_TAG_DUMMY
);
if
(
pExprList
->
a
[
0
].
aliasName
!=
NULL
)
{
strncpy
(
pExpr1
->
aliasName
,
pExprList
->
a
[
0
].
aliasName
,
tListLen
(
pExpr1
->
aliasName
));
}
else
{
strncpy
(
pExpr1
->
aliasName
,
functionsInfo
[
index
].
name
,
tListLen
(
pExpr1
->
aliasName
));
}
switch
(
index
)
{
case
0
:
pCmd
->
command
=
TSDB_SQL_CURRENT_DB
;
return
TSDB_CODE_SUCCESS
;
case
1
:
pCmd
->
command
=
TSDB_SQL_SERV_VERSION
;
return
TSDB_CODE_SUCCESS
;
case
2
:
pCmd
->
command
=
TSDB_SQL_SERV_STATUS
;
return
TSDB_CODE_SUCCESS
;
case
3
:
pCmd
->
command
=
TSDB_SQL_CLI_VERSION
;
return
TSDB_CODE_SUCCESS
;
case
4
:
pCmd
->
command
=
TSDB_SQL_CURRENT_USER
;
return
TSDB_CODE_SUCCESS
;
default:
{
setErrMsg
(
pCmd
,
msg3
);
return
TSDB_CODE_INVALID_SQL
;
}
}
}
src/client/src/tscSQLParserImpl.c
浏览文件 @
a797219b
...
...
@@ -500,7 +500,7 @@ void tSQLSetColumnType(TAOS_FIELD *pField, SSQLToken *type) {
SQuerySQL
*
tSetQuerySQLElems
(
SSQLToken
*
pSelectToken
,
tSQLExprList
*
pSelection
,
tVariantList
*
pFrom
,
tSQLExpr
*
pWhere
,
tVariantList
*
pGroupby
,
tVariantList
*
pSortOrder
,
SSQLToken
*
pInterval
,
SSQLToken
*
pSliding
,
tVariantList
*
pFill
,
SLimitVal
*
pLimit
,
SLimitVal
*
pGLimit
)
{
assert
(
pSelection
!=
NULL
&&
pFrom
!=
NULL
&&
pInterval
!=
NULL
&&
pLimit
!=
NULL
&&
pGLimit
!=
NULL
);
assert
(
pSelection
!=
NULL
);
SQuerySQL
*
pQuery
=
calloc
(
1
,
sizeof
(
SQuerySQL
));
pQuery
->
selectToken
=
*
pSelectToken
;
...
...
@@ -512,13 +512,23 @@ SQuerySQL *tSetQuerySQLElems(SSQLToken *pSelectToken, tSQLExprList *pSelection,
pQuery
->
pSortOrder
=
pSortOrder
;
pQuery
->
pWhere
=
pWhere
;
pQuery
->
limit
=
*
pLimit
;
pQuery
->
slimit
=
*
pGLimit
;
if
(
pLimit
!=
NULL
)
{
pQuery
->
limit
=
*
pLimit
;
}
if
(
pGLimit
!=
NULL
)
{
pQuery
->
slimit
=
*
pGLimit
;
}
pQuery
->
interval
=
*
pInterval
;
pQuery
->
sliding
=
*
pSliding
;
if
(
pInterval
!=
NULL
)
{
pQuery
->
interval
=
*
pInterval
;
}
if
(
pSliding
!=
NULL
)
{
pQuery
->
sliding
=
*
pSliding
;
}
pQuery
->
fillType
=
pFill
;
return
pQuery
;
}
...
...
src/client/src/tscServer.c
浏览文件 @
a797219b
...
...
@@ -3807,7 +3807,14 @@ void tscInitMsgs() {
tscProcessMsgRsp
[
TSDB_SQL_SHOW
]
=
tscProcessShowRsp
;
tscProcessMsgRsp
[
TSDB_SQL_RETRIEVE
]
=
tscProcessRetrieveRspFromVnode
;
// rsp handled by same function.
tscProcessMsgRsp
[
TSDB_SQL_DESCRIBE_TABLE
]
=
tscProcessDescribeTableRsp
;
tscProcessMsgRsp
[
TSDB_SQL_RETRIEVE_TAGS
]
=
tscProcessTagRetrieveRsp
;
tscProcessMsgRsp
[
TSDB_SQL_CURRENT_DB
]
=
tscProcessTagRetrieveRsp
;
tscProcessMsgRsp
[
TSDB_SQL_CURRENT_USER
]
=
tscProcessTagRetrieveRsp
;
tscProcessMsgRsp
[
TSDB_SQL_SERV_VERSION
]
=
tscProcessTagRetrieveRsp
;
tscProcessMsgRsp
[
TSDB_SQL_CLI_VERSION
]
=
tscProcessTagRetrieveRsp
;
tscProcessMsgRsp
[
TSDB_SQL_SERV_STATUS
]
=
tscProcessTagRetrieveRsp
;
tscProcessMsgRsp
[
TSDB_SQL_RETRIEVE_EMPTY_RESULT
]
=
tscProcessEmptyResultRsp
;
tscProcessMsgRsp
[
TSDB_SQL_RETRIEVE_METRIC
]
=
tscProcessRetrieveMetricRsp
;
...
...
src/client/src/tscUtil.c
浏览文件 @
a797219b
...
...
@@ -720,7 +720,7 @@ static void evic(SFieldInfo* pFieldInfo, int32_t index) {
}
}
static
void
setValueImpl
(
TAOS_FIELD
*
pField
,
int8_t
type
,
char
*
name
,
int16_t
bytes
)
{
static
void
setValueImpl
(
TAOS_FIELD
*
pField
,
int8_t
type
,
c
onst
c
har
*
name
,
int16_t
bytes
)
{
pField
->
type
=
type
;
strncpy
(
pField
->
name
,
name
,
TSDB_COL_NAME_LEN
);
pField
->
bytes
=
bytes
;
...
...
@@ -764,7 +764,7 @@ void tscFieldInfoUpdateVisible(SFieldInfo* pFieldInfo, int32_t index, bool visib
}
}
void
tscFieldInfoSetValue
(
SFieldInfo
*
pFieldInfo
,
int32_t
index
,
int8_t
type
,
char
*
name
,
int16_t
bytes
)
{
void
tscFieldInfoSetValue
(
SFieldInfo
*
pFieldInfo
,
int32_t
index
,
int8_t
type
,
c
onst
c
har
*
name
,
int16_t
bytes
)
{
ensureSpace
(
pFieldInfo
,
pFieldInfo
->
numOfOutputCols
+
1
);
evic
(
pFieldInfo
,
index
);
...
...
@@ -896,6 +896,19 @@ static void _exprEvic(SSqlExprInfo* pExprInfo, int32_t index) {
}
}
SSqlExpr
*
tscSqlExprInsertEmpty
(
SSqlCmd
*
pCmd
,
int32_t
index
,
int16_t
functionId
)
{
SSqlExprInfo
*
pExprInfo
=
&
pCmd
->
exprsInfo
;
_exprCheckSpace
(
pExprInfo
,
pExprInfo
->
numOfExprs
+
1
);
_exprEvic
(
pExprInfo
,
index
);
SSqlExpr
*
pExpr
=
&
pExprInfo
->
pExprs
[
index
];
pExpr
->
functionId
=
functionId
;
pExprInfo
->
numOfExprs
++
;
return
pExpr
;
}
SSqlExpr
*
tscSqlExprInsert
(
SSqlCmd
*
pCmd
,
int32_t
index
,
int16_t
functionId
,
SColumnIndex
*
pColIndex
,
int16_t
type
,
int16_t
size
,
int16_t
interSize
)
{
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
pCmd
,
pColIndex
->
tableIndex
);
...
...
src/inc/sql.y
浏览文件 @
a797219b
...
...
@@ -349,6 +349,14 @@ select(A) ::= SELECT(T) selcollist(W) from(X) where_opt(Y) interval_opt(K) fill_
A = tSetQuerySQLElems(&T, W, X, Y, P, Z, &K, &S, F, &L, &G);
}
// Support for the SQL exprssion without from & where subclauses, e.g.,
// select current_database(),
// select server_version(), select client_version(),
// select server_state();
select(A) ::= SELECT(T) selcollist(W). {
A = tSetQuerySQLElems(&T, W, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
}
// selcollist is a list of expressions that are to become the return
// values of the SELECT statement. The "*" in statements like
// "SELECT * FROM ..." is encoded as a special expression with an opcode of TK_ALL.
...
...
@@ -391,7 +399,7 @@ tmvar(A) ::= VARIABLE(X). {A = X;}
%type interval_opt {SSQLToken}
interval_opt(N) ::= INTERVAL LP tmvar(E) RP. {N = E; }
interval_opt(N) ::= . {N.n = 0; }
interval_opt(N) ::= . {N.n = 0;
N.z = NULL; N.type = 0;
}
%type fill_opt {tVariantList*}
%destructor fill_opt {tVariantListDestroy($$);}
...
...
@@ -412,7 +420,7 @@ fill_opt(N) ::= FILL LP ID(Y) RP. {
%type sliding_opt {SSQLToken}
sliding_opt(K) ::= SLIDING LP tmvar(E) RP. {K = E; }
sliding_opt(K) ::= . {K.n = 0; }
sliding_opt(K) ::= . {K.n = 0;
K.z = NULL; K.type = 0;
}
%type orderby_opt {tVariantList*}
%destructor orderby_opt {tVariantListDestroy($$);}
...
...
src/util/src/sql.c
浏览文件 @
a797219b
此差异已折叠。
点击以展开。
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录