Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
574f9d4c
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
574f9d4c
编写于
11月 27, 2019
作者:
S
slguan
提交者:
GitHub
11月 27, 2019
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #786 from taosdata/feature/liaohj
[tbase-874]
上级
7570c7ff
f0b93abb
变更
13
显示空白变更内容
内联
并排
Showing
13 changed file
with
443 addition
and
714 deletion
+443
-714
src/client/inc/tsclient.h
src/client/inc/tsclient.h
+40
-47
src/client/src/tscAsync.c
src/client/src/tscAsync.c
+3
-3
src/client/src/tscParseInsert.c
src/client/src/tscParseInsert.c
+80
-121
src/client/src/tscSQLParser.c
src/client/src/tscSQLParser.c
+256
-460
src/client/src/tscSchemaUtil.c
src/client/src/tscSchemaUtil.c
+1
-0
src/client/src/tscServer.c
src/client/src/tscServer.c
+2
-29
src/client/src/tscSql.c
src/client/src/tscSql.c
+18
-10
src/client/src/tscUtil.c
src/client/src/tscUtil.c
+26
-2
src/inc/taosmsg.h
src/inc/taosmsg.h
+0
-1
src/system/detail/inc/vnode.h
src/system/detail/inc/vnode.h
+1
-1
src/system/detail/src/vnodeQueryImpl.c
src/system/detail/src/vnodeQueryImpl.c
+11
-29
src/system/detail/src/vnodeRead.c
src/system/detail/src/vnodeRead.c
+4
-7
src/system/detail/src/vnodeShell.c
src/system/detail/src/vnodeShell.c
+1
-4
未找到文件。
src/client/inc/tsclient.h
浏览文件 @
574f9d4c
...
...
@@ -34,8 +34,8 @@ extern "C" {
#include "tglobalcfg.h"
#include "tlog.h"
#include "tscCache.h"
#include "tsdb.h"
#include "tscSQLParser.h"
#include "tsdb.h"
#include "tsqlfunction.h"
#include "tutil.h"
...
...
@@ -247,7 +247,7 @@ typedef struct STableDataBlocks {
// for parameter ('?') binding
uint32_t
numOfAllocedParams
;
uint32_t
numOfParams
;
SParamInfo
*
params
;
SParamInfo
*
params
;
}
STableDataBlocks
;
typedef
struct
SDataBlockList
{
...
...
@@ -262,18 +262,17 @@ typedef struct SDataBlockList {
typedef
struct
{
SOrderVal
order
;
int
command
;
// TODO refactor
int
count
;
int16_t
isInsertFromFile
;
// load data from file or not
int
count
;
// TODO refactor
union
{
bool
existsCheck
;
int8_t
showType
;
bool
existsCheck
;
// check if the table exists
int8_t
showType
;
// show command type
int8_t
isInsertFromFile
;
// load data from file or not
};
bool
import
;
// import/insert type
char
msgType
;
uint16_t
type
;
uint16_t
type
;
// query type
char
intervalTimeUnit
;
int64_t
etime
,
stime
;
int64_t
nAggTimeInterval
;
// aggregation time interval
...
...
@@ -450,12 +449,6 @@ int taos_retrieve(TAOS_RES *res);
int32_t
tscTansformSQLFunctionForMetricQuery
(
SSqlCmd
*
pCmd
);
void
tscRestoreSQLFunctionForMetricQuery
(
SSqlCmd
*
pCmd
);
/**
* release both metric/meter meta information
* @param pCmd SSqlCmd object that contains the metric/meter meta info
*/
void
tscClearSqlMetaInfo
(
SSqlCmd
*
pCmd
);
void
tscClearSqlMetaInfoForce
(
SSqlCmd
*
pCmd
);
int32_t
tscCreateResPointerInfo
(
SSqlCmd
*
pCmd
,
SSqlRes
*
pRes
);
...
...
@@ -483,8 +476,8 @@ void tscProcessMultiVnodesInsert(SSqlObj *pSql);
void
tscProcessMultiVnodesInsertForFile
(
SSqlObj
*
pSql
);
void
tscKillMetricQuery
(
SSqlObj
*
pSql
);
void
tscInitResObjForLocalQuery
(
SSqlObj
*
pObj
,
int32_t
numOfRes
,
int32_t
rowLen
);
int32_t
tscBuildResultsForEmptyRetrieval
(
SSqlObj
*
pSql
);
bool
tscIsUpdateQuery
(
STscObj
*
pObj
);
int32_t
tscInvalidSQLErrMsg
(
char
*
msg
,
const
char
*
additionalInfo
,
const
char
*
sql
);
// transfer SSqlInfo to SqlCmd struct
int32_t
tscToSQLCmd
(
SSqlObj
*
pSql
,
struct
SSqlInfo
*
pInfo
);
...
...
src/client/src/tscAsync.c
浏览文件 @
574f9d4c
...
...
@@ -40,6 +40,7 @@ static void tscProcessAsyncRetrieveImpl(void *param, TAOS_RES *tres, int numOfRo
*/
static
void
tscProcessAsyncFetchRowsProxy
(
void
*
param
,
TAOS_RES
*
tres
,
int
numOfRows
);
// TODO return the correct error code to client in tscQueueAsyncError
void
taos_query_a
(
TAOS
*
taos
,
const
char
*
sqlstr
,
void
(
*
fp
)(
void
*
,
TAOS_RES
*
,
int
),
void
*
param
)
{
STscObj
*
pObj
=
(
STscObj
*
)
taos
;
if
(
pObj
==
NULL
||
pObj
->
signature
!=
pObj
)
{
...
...
@@ -58,14 +59,13 @@ void taos_query_a(TAOS *taos, const char *sqlstr, void (*fp)(void *, TAOS_RES *,
taosNotePrintTsc
(
sqlstr
);
SSqlObj
*
pSql
=
(
SSqlObj
*
)
malloc
(
sizeof
(
SSqlObj
));
SSqlObj
*
pSql
=
(
SSqlObj
*
)
calloc
(
1
,
sizeof
(
SSqlObj
));
if
(
pSql
==
NULL
)
{
tscError
(
"failed to malloc sqlObj"
);
tscQueueAsyncError
(
fp
,
param
);
return
;
}
memset
(
pSql
,
0
,
sizeof
(
SSqlObj
));
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SSqlRes
*
pRes
=
&
pSql
->
res
;
...
...
src/client/src/tscParseInsert.c
浏览文件 @
574f9d4c
...
...
@@ -34,18 +34,11 @@
#include "tstoken.h"
#include "ttime.h"
#define INVALID_SQL_RET_MSG(p, ...) \
do { \
sprintf(p, __VA_ARGS__); \
return TSDB_CODE_INVALID_SQL; \
} while (0)
enum
{
TSDB_USE_SERVER_TS
=
0
,
TSDB_USE_CLI_TS
=
1
,
};
static
void
setErrMsg
(
char
*
msg
,
const
char
*
sql
);
static
int32_t
tscAllocateMemIfNeed
(
STableDataBlocks
*
pDataBlock
,
int32_t
rowSize
);
static
int32_t
tscToInteger
(
SSQLToken
*
pToken
,
int64_t
*
value
,
char
**
endPtr
)
{
...
...
@@ -97,7 +90,7 @@ int tsParseTime(SSQLToken *pToken, int64_t *time, char **next, char *error, int1
}
else
{
// strptime("2001-11-12 18:31:01", "%Y-%m-%d %H:%M:%S", &tm);
if
(
taosParseTime
(
pToken
->
z
,
time
,
pToken
->
n
,
timePrec
)
!=
TSDB_CODE_SUCCESS
)
{
return
TSDB_CODE_INVALID_SQL
;
return
tscInvalidSQLErrMsg
(
error
,
"invalid timestamp format"
,
pToken
->
z
)
;
}
return
TSDB_CODE_SUCCESS
;
...
...
@@ -122,18 +115,21 @@ int tsParseTime(SSQLToken *pToken, int64_t *time, char **next, char *error, int1
index
=
0
;
sToken
=
tStrGetToken
(
pTokenEnd
,
&
index
,
false
,
0
,
NULL
);
pTokenEnd
+=
index
;
if
(
sToken
.
type
==
TK_MINUS
||
sToken
.
type
==
TK_PLUS
)
{
index
=
0
;
valueToken
=
tStrGetToken
(
pTokenEnd
,
&
index
,
false
,
0
,
NULL
);
pTokenEnd
+=
index
;
if
(
valueToken
.
n
<
2
)
{
strcpy
(
error
,
"value is expected"
);
return
TSDB_CODE_INVALID_SQL
;
return
tscInvalidSQLErrMsg
(
error
,
"value expected in timestamp"
,
sToken
.
z
);
}
if
(
getTimestampInUsFromStr
(
valueToken
.
z
,
valueToken
.
n
,
&
interval
)
!=
TSDB_CODE_SUCCESS
)
{
return
TSDB_CODE_INVALID_SQL
;
}
if
(
timePrec
==
TSDB_TIME_PRECISION_MILLI
)
{
interval
/=
1000
;
}
...
...
@@ -156,7 +152,6 @@ int32_t tsParseOneColumnData(SSchema *pSchema, SSQLToken *pToken, char *payload,
int64_t
iv
;
int32_t
numType
;
char
*
endptr
=
NULL
;
errno
=
0
;
// reset global error code
switch
(
pSchema
->
type
)
{
case
TSDB_DATA_TYPE_BOOL
:
{
// bool
...
...
@@ -168,7 +163,7 @@ int32_t tsParseOneColumnData(SSchema *pSchema, SSQLToken *pToken, char *payload,
}
else
if
(
strncasecmp
(
TSDB_DATA_NULL_STR_L
,
pToken
->
z
,
pToken
->
n
)
==
0
)
{
*
(
uint8_t
*
)
payload
=
TSDB_DATA_BOOL_NULL
;
}
else
{
INVALID_SQL_RET_MSG
(
msg
,
"data is illegal"
);
return
tscInvalidSQLErrMsg
(
msg
,
"invalid bool data"
,
pToken
->
z
);
}
}
else
if
(
pToken
->
type
==
TK_INTEGER
)
{
iv
=
strtoll
(
pToken
->
z
,
NULL
,
10
);
...
...
@@ -179,7 +174,7 @@ int32_t tsParseOneColumnData(SSchema *pSchema, SSQLToken *pToken, char *payload,
}
else
if
(
pToken
->
type
==
TK_NULL
)
{
*
(
uint8_t
*
)
payload
=
TSDB_DATA_BOOL_NULL
;
}
else
{
INVALID_SQL_RET_MSG
(
msg
,
"data is illegal"
);
return
tscInvalidSQLErrMsg
(
msg
,
"invalid bool data"
,
pToken
->
z
);
}
break
;
}
...
...
@@ -192,12 +187,12 @@ int32_t tsParseOneColumnData(SSchema *pSchema, SSQLToken *pToken, char *payload,
}
else
{
numType
=
tscToInteger
(
pToken
,
&
iv
,
&
endptr
);
if
(
TK_ILLEGAL
==
numType
)
{
INVALID_SQL_RET_MSG
(
msg
,
"data is illegal"
);
return
tscInvalidSQLErrMsg
(
msg
,
"invalid tinyint data"
,
pToken
->
z
);
}
else
if
(
errno
==
ERANGE
||
iv
>
INT8_MAX
||
iv
<=
INT8_MIN
)
{
INVALID_SQL_RET_MSG
(
msg
,
"data is overflow"
);
return
tscInvalidSQLErrMsg
(
msg
,
"tinyint data overflow"
,
pToken
->
z
);
}
*
((
int8_t
*
)
payload
)
=
(
int8_t
)
iv
;
*
((
int8_t
*
)
payload
)
=
(
int8_t
)
iv
;
}
break
;
...
...
@@ -211,9 +206,9 @@ int32_t tsParseOneColumnData(SSchema *pSchema, SSQLToken *pToken, char *payload,
}
else
{
numType
=
tscToInteger
(
pToken
,
&
iv
,
&
endptr
);
if
(
TK_ILLEGAL
==
numType
)
{
INVALID_SQL_RET_MSG
(
msg
,
"data is illegal"
);
return
tscInvalidSQLErrMsg
(
msg
,
"invalid smallint data"
,
pToken
->
z
);
}
else
if
(
errno
==
ERANGE
||
iv
>
INT16_MAX
||
iv
<=
INT16_MIN
)
{
INVALID_SQL_RET_MSG
(
msg
,
"data is overflow"
);
return
tscInvalidSQLErrMsg
(
msg
,
"smallint data overflow"
,
pToken
->
z
);
}
*
((
int16_t
*
)
payload
)
=
(
int16_t
)
iv
;
...
...
@@ -229,9 +224,9 @@ int32_t tsParseOneColumnData(SSchema *pSchema, SSQLToken *pToken, char *payload,
}
else
{
numType
=
tscToInteger
(
pToken
,
&
iv
,
&
endptr
);
if
(
TK_ILLEGAL
==
numType
)
{
INVALID_SQL_RET_MSG
(
msg
,
"data is illegal"
);
return
tscInvalidSQLErrMsg
(
msg
,
"invalid int data"
,
pToken
->
z
);
}
else
if
(
errno
==
ERANGE
||
iv
>
INT32_MAX
||
iv
<=
INT32_MIN
)
{
INVALID_SQL_RET_MSG
(
msg
,
"data is overflow"
);
return
tscInvalidSQLErrMsg
(
msg
,
"int data overflow"
,
pToken
->
z
);
}
*
((
int32_t
*
)
payload
)
=
(
int32_t
)
iv
;
...
...
@@ -248,9 +243,9 @@ int32_t tsParseOneColumnData(SSchema *pSchema, SSQLToken *pToken, char *payload,
}
else
{
numType
=
tscToInteger
(
pToken
,
&
iv
,
&
endptr
);
if
(
TK_ILLEGAL
==
numType
)
{
INVALID_SQL_RET_MSG
(
msg
,
"data is illegal"
);
return
tscInvalidSQLErrMsg
(
msg
,
"invalid bigint data"
,
pToken
->
z
);
}
else
if
(
errno
==
ERANGE
||
iv
>
INT64_MAX
||
iv
<=
INT64_MIN
)
{
INVALID_SQL_RET_MSG
(
msg
,
"data is overflow"
);
return
tscInvalidSQLErrMsg
(
msg
,
"bigint data overflow"
,
pToken
->
z
);
}
*
((
int64_t
*
)
payload
)
=
iv
;
...
...
@@ -266,12 +261,12 @@ int32_t tsParseOneColumnData(SSchema *pSchema, SSQLToken *pToken, char *payload,
}
else
{
double
dv
;
if
(
TK_ILLEGAL
==
tscToDouble
(
pToken
,
&
dv
,
&
endptr
))
{
INVALID_SQL_RET_MSG
(
msg
,
"data is illegal"
);
return
tscInvalidSQLErrMsg
(
msg
,
"illegal float data"
,
pToken
->
z
);
}
float
fv
=
(
float
)
dv
;
if
(((
dv
==
HUGE_VAL
||
dv
==
-
HUGE_VAL
)
&&
errno
==
ERANGE
)
||
(
fv
>
FLT_MAX
||
fv
<
-
FLT_MAX
))
{
INVALID_SQL_RET_MSG
(
msg
,
"data is illegal"
);
return
tscInvalidSQLErrMsg
(
msg
,
"illegal float data"
,
pToken
->
z
);
}
if
(
isinf
(
fv
)
||
isnan
(
fv
))
{
...
...
@@ -291,11 +286,11 @@ int32_t tsParseOneColumnData(SSchema *pSchema, SSQLToken *pToken, char *payload,
}
else
{
double
dv
;
if
(
TK_ILLEGAL
==
tscToDouble
(
pToken
,
&
dv
,
&
endptr
))
{
INVALID_SQL_RET_MSG
(
msg
,
"data is illegal"
);
return
tscInvalidSQLErrMsg
(
msg
,
"illegal double data"
,
pToken
->
z
);
}
if
(((
dv
==
HUGE_VAL
||
dv
==
-
HUGE_VAL
)
&&
errno
==
ERANGE
)
||
(
dv
>
DBL_MAX
||
dv
<
-
DBL_MAX
))
{
INVALID_SQL_RET_MSG
(
msg
,
"data is illegal"
);
return
tscInvalidSQLErrMsg
(
msg
,
"illegal double data"
,
pToken
->
z
);
}
if
(
isinf
(
dv
)
||
isnan
(
dv
))
{
...
...
@@ -310,11 +305,11 @@ int32_t tsParseOneColumnData(SSchema *pSchema, SSQLToken *pToken, char *payload,
// binary data cannot be null-terminated char string, otherwise the last char of the string is lost
if
(
pToken
->
type
==
TK_NULL
)
{
*
payload
=
TSDB_DATA_BINARY_NULL
;
}
else
{
// too long values will return invalid sql, not be truncated automatically
}
else
{
// too long values will return invalid sql, not be truncated automatically
if
(
pToken
->
n
>
pSchema
->
bytes
)
{
INVALID_SQL_RET_MSG
(
msg
,
"value too long"
);
return
tscInvalidSQLErrMsg
(
msg
,
"string data overflow"
,
pToken
->
z
);
}
strncpy
(
payload
,
pToken
->
z
,
pToken
->
n
);
}
...
...
@@ -326,8 +321,10 @@ int32_t tsParseOneColumnData(SSchema *pSchema, SSQLToken *pToken, char *payload,
}
else
{
// if the converted output len is over than pSchema->bytes, return error: 'Argument list too long'
if
(
!
taosMbsToUcs4
(
pToken
->
z
,
pToken
->
n
,
payload
,
pSchema
->
bytes
))
{
sprintf
(
msg
,
"%s"
,
strerror
(
errno
));
return
TSDB_CODE_INVALID_SQL
;
char
buf
[
512
]
=
{
0
};
snprintf
(
buf
,
512
,
"%s"
,
strerror
(
errno
));
return
tscInvalidSQLErrMsg
(
msg
,
buf
,
pToken
->
z
);
}
}
break
;
...
...
@@ -342,8 +339,9 @@ int32_t tsParseOneColumnData(SSchema *pSchema, SSQLToken *pToken, char *payload,
}
else
{
int64_t
temp
;
if
(
tsParseTime
(
pToken
,
&
temp
,
str
,
msg
,
timePrec
)
!=
TSDB_CODE_SUCCESS
)
{
return
TSDB_CODE_INVALID_SQL
;
return
tscInvalidSQLErrMsg
(
msg
,
"invalid timestamp"
,
pToken
->
z
)
;
}
*
((
int64_t
*
)
payload
)
=
temp
;
}
...
...
@@ -351,18 +349,7 @@ int32_t tsParseOneColumnData(SSchema *pSchema, SSQLToken *pToken, char *payload,
}
}
return
0
;
}
// todo merge the error msg function with tSQLParser
static
void
setErrMsg
(
char
*
msg
,
const
char
*
sql
)
{
const
char
*
msgFormat
=
"near
\"
%s
\"
syntax error"
;
const
int32_t
BACKWARD_CHAR_STEP
=
15
;
// only extract part of sql string,avoid too long sql string cause stack over flow
char
buf
[
64
]
=
{
0
};
strncpy
(
buf
,
(
sql
-
BACKWARD_CHAR_STEP
),
tListLen
(
buf
)
-
1
);
sprintf
(
msg
,
msgFormat
,
buf
);
return
TSDB_CODE_SUCCESS
;
}
/*
...
...
@@ -385,7 +372,8 @@ static int32_t tsCheckTimestamp(STableDataBlocks *pDataBlocks, const char *start
}
}
else
{
if
(
pDataBlocks
->
tsSource
==
TSDB_USE_SERVER_TS
)
{
return
-
1
;
return
-
1
;
// client time/server time can not be mixed
}
else
if
(
pDataBlocks
->
tsSource
==
-
1
)
{
pDataBlocks
->
tsSource
=
TSDB_USE_CLI_TS
;
}
...
...
@@ -403,7 +391,7 @@ int tsParseOneRowData(char **str, STableDataBlocks *pDataBlocks, SSchema schema[
int16_t
timePrec
)
{
int32_t
index
=
0
;
bool
isPrevOptr
;
SSQLToken
sToken
;
SSQLToken
sToken
=
{
0
}
;
char
*
payload
=
pDataBlocks
->
pData
+
pDataBlocks
->
size
;
// 1. set the parsed value from sql string
...
...
@@ -424,6 +412,7 @@ int tsParseOneRowData(char **str, STableDataBlocks *pDataBlocks, SSchema schema[
if
(
tscAddParamToDataBlock
(
pDataBlocks
,
pSchema
->
type
,
(
uint8_t
)
timePrec
,
pSchema
->
bytes
,
offset
)
!=
NULL
)
{
continue
;
}
strcpy
(
error
,
"client out of memory"
);
return
-
1
;
}
...
...
@@ -431,7 +420,7 @@ int tsParseOneRowData(char **str, STableDataBlocks *pDataBlocks, SSchema schema[
if
(((
sToken
.
type
!=
TK_NOW
)
&&
(
sToken
.
type
!=
TK_INTEGER
)
&&
(
sToken
.
type
!=
TK_STRING
)
&&
(
sToken
.
type
!=
TK_FLOAT
)
&&
(
sToken
.
type
!=
TK_BOOL
)
&&
(
sToken
.
type
!=
TK_NULL
))
||
(
sToken
.
n
==
0
)
||
(
sToken
.
type
==
TK_RP
))
{
setErrMsg
(
error
,
*
str
);
tscInvalidSQLErrMsg
(
error
,
"invalid data or symbol"
,
sToken
.
z
);
return
-
1
;
}
...
...
@@ -448,6 +437,7 @@ int tsParseOneRowData(char **str, STableDataBlocks *pDataBlocks, SSchema schema[
}
if
(
isPrimaryKey
&&
tsCheckTimestamp
(
pDataBlocks
,
start
)
!=
TSDB_CODE_SUCCESS
)
{
tscInvalidSQLErrMsg
(
error
,
"client time/server time can not be mixed up"
,
sToken
.
z
);
return
-
1
;
}
}
...
...
@@ -457,8 +447,7 @@ int tsParseOneRowData(char **str, STableDataBlocks *pDataBlocks, SSchema schema[
char
*
ptr
=
payload
;
for
(
int32_t
i
=
0
;
i
<
spd
->
numOfCols
;
++
i
)
{
if
(
!
spd
->
hasVal
[
i
])
{
// current column do not have any value to insert, set it to null
if
(
!
spd
->
hasVal
[
i
])
{
// current column do not have any value to insert, set it to null
setNull
(
ptr
,
schema
[
i
].
type
,
schema
[
i
].
bytes
);
}
...
...
@@ -513,8 +502,7 @@ int tsParseValues(char **str, STableDataBlocks *pDataBlock, SMeterMeta *pMeterMe
}
int32_t
len
=
tsParseOneRowData
(
str
,
pDataBlock
,
pSchema
,
spd
,
error
,
precision
);
if
(
len
<=
0
)
{
setErrMsg
(
error
,
*
str
);
if
(
len
<=
0
)
{
// error message has been set in tsParseOneRowData
return
-
1
;
}
...
...
@@ -524,7 +512,7 @@ int tsParseValues(char **str, STableDataBlocks *pDataBlock, SMeterMeta *pMeterMe
sToken
=
tStrGetToken
(
*
str
,
&
index
,
false
,
0
,
NULL
);
*
str
+=
index
;
if
(
sToken
.
n
==
0
||
sToken
.
type
!=
TK_RP
)
{
setErrMsg
(
error
,
*
str
);
tscInvalidSQLErrMsg
(
error
,
") expected"
,
*
str
);
return
-
1
;
}
...
...
@@ -719,8 +707,7 @@ static int32_t tscParseSqlForCreateTableOnDemand(char **sqlstr, SSqlObj *pSql) {
return
TSDB_CODE_INVALID_SQL
;
}
if
(
sToken
.
type
==
TK_USING
)
{
// create table if not exists
if
(
sToken
.
type
==
TK_USING
)
{
// create table if not exists
index
=
0
;
sToken
=
tStrGetToken
(
sql
,
&
index
,
false
,
0
,
NULL
);
sql
+=
index
;
...
...
@@ -736,8 +723,7 @@ static int32_t tscParseSqlForCreateTableOnDemand(char **sqlstr, SSqlObj *pSql) {
}
if
(
!
UTIL_METER_IS_METRIC
(
pMeterMetaInfo
))
{
strcpy
(
pCmd
->
payload
,
"create table only from super table is allowed"
);
return
TSDB_CODE_INVALID_SQL
;
return
tscInvalidSQLErrMsg
(
pCmd
->
payload
,
"create table only from super table is allowed"
,
sToken
.
z
);
}
char
*
tagVal
=
pTag
->
data
;
...
...
@@ -747,8 +733,7 @@ static int32_t tscParseSqlForCreateTableOnDemand(char **sqlstr, SSqlObj *pSql) {
sToken
=
tStrGetToken
(
sql
,
&
index
,
false
,
0
,
NULL
);
sql
+=
index
;
if
(
sToken
.
type
!=
TK_TAGS
)
{
setErrMsg
(
pCmd
->
payload
,
sql
);
return
TSDB_CODE_INVALID_SQL
;
return
tscInvalidSQLErrMsg
(
pCmd
->
payload
,
"keyword TAGS expected"
,
sql
);
}
int32_t
numOfTagValues
=
0
;
...
...
@@ -773,28 +758,23 @@ static int32_t tscParseSqlForCreateTableOnDemand(char **sqlstr, SSqlObj *pSql) {
code
=
tsParseOneColumnData
(
&
pTagSchema
[
numOfTagValues
],
&
sToken
,
tagVal
,
pCmd
->
payload
,
&
sql
,
false
,
pMeterMetaInfo
->
pMeterMeta
->
precision
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
setErrMsg
(
pCmd
->
payload
,
sql
);
return
TSDB_CODE_INVALID_SQL
;
return
code
;
}
if
((
pTagSchema
[
numOfTagValues
].
type
==
TSDB_DATA_TYPE_BINARY
||
pTagSchema
[
numOfTagValues
].
type
==
TSDB_DATA_TYPE_NCHAR
)
&&
sToken
.
n
>
pTagSchema
[
numOfTagValues
].
bytes
)
{
strcpy
(
pCmd
->
payload
,
"tag value too long"
);
return
TSDB_CODE_INVALID_SQL
;
pTagSchema
[
numOfTagValues
].
type
==
TSDB_DATA_TYPE_NCHAR
)
&&
sToken
.
n
>
pTagSchema
[
numOfTagValues
].
bytes
)
{
return
tscInvalidSQLErrMsg
(
pCmd
->
payload
,
"string too long"
,
sToken
.
z
);
}
tagVal
+=
pTagSchema
[
numOfTagValues
++
].
bytes
;
}
if
(
numOfTagValues
!=
pMeterMetaInfo
->
pMeterMeta
->
numOfTags
)
{
setErrMsg
(
pCmd
->
payload
,
sql
);
return
TSDB_CODE_INVALID_SQL
;
return
tscInvalidSQLErrMsg
(
pCmd
->
payload
,
"number of tags mismatch"
,
sql
);
}
if
(
tscValidateName
(
&
tableToken
)
!=
TSDB_CODE_SUCCESS
)
{
setErrMsg
(
pCmd
->
payload
,
sql
);
return
TSDB_CODE_INVALID_SQL
;
return
tscInvalidSQLErrMsg
(
pCmd
->
payload
,
"invalid table name"
,
sql
);
}
int32_t
ret
=
setMeterID
(
pSql
,
&
tableToken
,
0
);
...
...
@@ -844,25 +824,19 @@ int validateTableName(char *tblName, int len) {
* @param pSql
* @return
*/
int
tsParseInsertStatement
(
SSqlObj
*
pSql
,
char
*
str
,
char
*
acct
,
char
*
db
)
{
int
doParserInsertSql
(
SSqlObj
*
pSql
,
char
*
str
)
{
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
pCmd
->
command
=
TSDB_SQL_INSERT
;
pCmd
->
isInsertFromFile
=
-
1
;
pCmd
->
count
=
0
;
pSql
->
res
.
numOfRows
=
0
;
int32_t
code
=
TSDB_CODE_INVALID_SQL
;
int32_t
totalNum
=
0
;
int
code
=
TSDB_CODE_INVALID_SQL
;
SMeterMetaInfo
*
pMeterMetaInfo
=
tscAddEmptyMeterMetaInfo
(
pCmd
);
if
((
code
=
tscAllocPayload
(
pCmd
,
TSDB_PAYLOAD_SIZE
))
!=
TSDB_CODE_SUCCESS
)
{
return
code
;
}
void
*
pTableHashList
=
taosInitIntHash
(
128
,
sizeof
(
void
*
)
,
taosHashInt
);
void
*
pTableHashList
=
taosInitIntHash
(
128
,
POINTER_BYTES
,
taosHashInt
);
pSql
->
cmd
.
pDataBlocks
=
tscCreateBlockArrayList
();
tscTrace
(
"%p create data block list for submit data, %p"
,
pSql
,
pSql
->
cmd
.
pDataBlocks
);
...
...
@@ -885,11 +859,11 @@ int tsParseInsertStatement(SSqlObj *pSql, char *str, char *acct, char *db) {
// Check if the table name available or not
if
(
validateTableName
(
sToken
.
z
,
sToken
.
n
)
!=
TSDB_CODE_SUCCESS
)
{
code
=
TSDB_CODE_INVALID_SQL
;
sprintf
(
pCmd
->
payload
,
"table name is invalid"
);
code
=
tscInvalidSQLErrMsg
(
pCmd
->
payload
,
"table name invalid"
,
sToken
.
z
);
goto
_error_clean
;
}
//TODO refactor
if
((
code
=
setMeterID
(
pSql
,
&
sToken
,
0
))
!=
TSDB_CODE_SUCCESS
)
{
goto
_error_clean
;
}
...
...
@@ -909,8 +883,7 @@ int tsParseInsertStatement(SSqlObj *pSql, char *str, char *acct, char *db) {
}
if
(
UTIL_METER_IS_METRIC
(
pMeterMetaInfo
))
{
code
=
TSDB_CODE_INVALID_SQL
;
sprintf
(
pCmd
->
payload
,
"insert data into metric is not supported"
);
code
=
tscInvalidSQLErrMsg
(
pCmd
->
payload
,
"insert data into super table is not supported"
,
NULL
);
goto
_error_clean
;
}
...
...
@@ -918,8 +891,7 @@ int tsParseInsertStatement(SSqlObj *pSql, char *str, char *acct, char *db) {
sToken
=
tStrGetToken
(
str
,
&
index
,
false
,
0
,
NULL
);
str
+=
index
;
if
(
sToken
.
n
==
0
)
{
code
=
TSDB_CODE_INVALID_SQL
;
sprintf
(
pCmd
->
payload
,
"keyword VALUES or FILE are required"
);
code
=
tscInvalidSQLErrMsg
(
pCmd
->
payload
,
"keyword VALUES or FILE are required"
,
sToken
.
z
);
goto
_error_clean
;
}
...
...
@@ -933,8 +905,7 @@ int tsParseInsertStatement(SSqlObj *pSql, char *str, char *acct, char *db) {
pCmd
->
isInsertFromFile
=
0
;
}
else
{
if
(
pCmd
->
isInsertFromFile
==
1
)
{
code
=
TSDB_CODE_INVALID_SQL
;
sprintf
(
pCmd
->
payload
,
"keyword VALUES and FILE are not allowed to mix up"
);
code
=
tscInvalidSQLErrMsg
(
pCmd
->
payload
,
"keyword VALUES and FILE are not allowed to mix up"
,
sToken
.
z
);
goto
_error_clean
;
}
}
...
...
@@ -953,8 +924,7 @@ int tsParseInsertStatement(SSqlObj *pSql, char *str, char *acct, char *db) {
pCmd
->
isInsertFromFile
=
1
;
}
else
{
if
(
pCmd
->
isInsertFromFile
==
0
)
{
code
=
TSDB_CODE_INVALID_SQL
;
sprintf
(
pCmd
->
payload
,
"keyword VALUES and FILE are not allowed to mix up"
);
code
=
tscInvalidSQLErrMsg
(
pCmd
->
payload
,
"keyword VALUES and FILE are not allowed to mix up"
,
sToken
.
z
);
goto
_error_clean
;
}
}
...
...
@@ -963,8 +933,7 @@ int tsParseInsertStatement(SSqlObj *pSql, char *str, char *acct, char *db) {
sToken
=
tStrGetToken
(
str
,
&
index
,
false
,
0
,
NULL
);
str
+=
index
;
if
(
sToken
.
n
==
0
)
{
code
=
TSDB_CODE_INVALID_SQL
;
sprintf
(
pCmd
->
payload
,
"file path is required following keyword FILE"
);
code
=
tscInvalidSQLErrMsg
(
pCmd
->
payload
,
"file path is required following keyword FILE"
,
sToken
.
z
);
goto
_error_clean
;
}
...
...
@@ -974,8 +943,7 @@ int tsParseInsertStatement(SSqlObj *pSql, char *str, char *acct, char *db) {
wordexp_t
full_path
;
if
(
wordexp
(
fname
,
&
full_path
,
0
)
!=
0
)
{
code
=
TSDB_CODE_INVALID_SQL
;
sprintf
(
pCmd
->
payload
,
"invalid filename"
);
code
=
tscInvalidSQLErrMsg
(
pCmd
->
payload
,
"invalid filename"
,
sToken
.
z
);
goto
_error_clean
;
}
strcpy
(
fname
,
full_path
.
we_wordv
[
0
]);
...
...
@@ -994,8 +962,7 @@ int tsParseInsertStatement(SSqlObj *pSql, char *str, char *acct, char *db) {
if
(
pCmd
->
isInsertFromFile
==
-
1
)
{
pCmd
->
isInsertFromFile
=
0
;
}
else
if
(
pCmd
->
isInsertFromFile
==
1
)
{
code
=
TSDB_CODE_INVALID_SQL
;
sprintf
(
pCmd
->
payload
,
"keyword VALUES and FILE are not allowed to mix up"
);
code
=
tscInvalidSQLErrMsg
(
pCmd
->
payload
,
"keyword VALUES and FILE are not allowed to mix up"
,
sToken
.
z
);
goto
_error_clean
;
}
...
...
@@ -1032,8 +999,7 @@ int tsParseInsertStatement(SSqlObj *pSql, char *str, char *acct, char *db) {
pElem
->
colIndex
=
t
;
if
(
spd
.
hasVal
[
t
]
==
true
)
{
code
=
TSDB_CODE_INVALID_SQL
;
sprintf
(
pCmd
->
payload
,
"duplicated column name"
);
code
=
tscInvalidSQLErrMsg
(
pCmd
->
payload
,
"duplicated column name"
,
sToken
.
z
);
goto
_error_clean
;
}
...
...
@@ -1044,15 +1010,13 @@ int tsParseInsertStatement(SSqlObj *pSql, char *str, char *acct, char *db) {
}
if
(
!
findColumnIndex
)
{
code
=
TSDB_CODE_INVALID_SQL
;
sprintf
(
pCmd
->
payload
,
"invalid column name"
);
code
=
tscInvalidSQLErrMsg
(
pCmd
->
payload
,
"invalid column name"
,
sToken
.
z
);
goto
_error_clean
;
}
}
if
(
spd
.
numOfAssignedCols
==
0
||
spd
.
numOfAssignedCols
>
pMeterMeta
->
numOfColumns
)
{
code
=
TSDB_CODE_INVALID_SQL
;
sprintf
(
pCmd
->
payload
,
"column name expected"
);
code
=
tscInvalidSQLErrMsg
(
pCmd
->
payload
,
"column name expected"
,
sToken
.
z
);
goto
_error_clean
;
}
...
...
@@ -1061,8 +1025,7 @@ int tsParseInsertStatement(SSqlObj *pSql, char *str, char *acct, char *db) {
str
+=
index
;
if
(
sToken
.
type
!=
TK_VALUES
)
{
code
=
TSDB_CODE_INVALID_SQL
;
sprintf
(
pCmd
->
payload
,
"keyword VALUES is expected"
);
code
=
tscInvalidSQLErrMsg
(
pCmd
->
payload
,
"keyword VALUES is expected"
,
sToken
.
z
);
goto
_error_clean
;
}
...
...
@@ -1071,8 +1034,7 @@ int tsParseInsertStatement(SSqlObj *pSql, char *str, char *acct, char *db) {
goto
_error_clean
;
}
}
else
{
code
=
TSDB_CODE_INVALID_SQL
;
sprintf
(
pCmd
->
payload
,
"keyword VALUES or FILE are required"
);
code
=
tscInvalidSQLErrMsg
(
pCmd
->
payload
,
"keyword VALUES or FILE are required"
,
sToken
.
z
);
goto
_error_clean
;
}
}
...
...
@@ -1120,25 +1082,21 @@ int tsParseInsertSql(SSqlObj *pSql, char *sql, char *acct, char *db) {
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SSQLToken
sToken
=
tStrGetToken
(
sql
,
&
index
,
false
,
0
,
NULL
);
if
(
sToken
.
type
==
TK_IMPORT
)
{
pCmd
->
order
.
order
=
TSQL_SO_ASC
;
}
else
if
(
sToken
.
type
!=
TK_INSERT
)
{
if
(
sToken
.
n
)
{
sToken
.
z
[
sToken
.
n
]
=
0
;
sprintf
(
pCmd
->
payload
,
"invalid keyword:%s"
,
sToken
.
z
);
}
else
{
strcpy
(
pCmd
->
payload
,
"no any keywords"
);
}
return
TSDB_CODE_INVALID_SQL
;
}
assert
(
sToken
.
type
==
TK_INSERT
||
sToken
.
type
==
TK_IMPORT
);
pCmd
->
import
=
(
sToken
.
type
==
TK_IMPORT
);
sToken
=
tStrGetToken
(
sql
,
&
index
,
false
,
0
,
NULL
);
if
(
sToken
.
type
!=
TK_INTO
)
{
strcpy
(
pCmd
->
payload
,
"keyword INTO is expected"
);
return
TSDB_CODE_INVALID_SQL
;
return
tscInvalidSQLErrMsg
(
pCmd
->
payload
,
"keyword INTO is expected"
,
sToken
.
z
);
}
return
tsParseInsertStatement
(
pSql
,
sql
+
index
,
acct
,
db
);
pCmd
->
count
=
0
;
pCmd
->
command
=
TSDB_SQL_INSERT
;
pCmd
->
isInsertFromFile
=
-
1
;
pSql
->
res
.
numOfRows
=
0
;
return
doParserInsertSql
(
pSql
,
sql
+
index
);
}
int
tsParseSql
(
SSqlObj
*
pSql
,
char
*
acct
,
char
*
db
,
bool
multiVnodeInsertion
)
{
...
...
@@ -1259,6 +1217,7 @@ static int tscInsertDataFromFile(SSqlObj *pSql, FILE *fp) {
pSql
->
res
.
code
=
TSDB_CODE_INVALID_SQL
;
return
-
1
;
}
pTableDataBlock
->
size
+=
len
;
count
++
;
...
...
src/client/src/tscSQLParser.c
浏览文件 @
574f9d4c
...
...
@@ -62,17 +62,15 @@ static bool validateTagParams(tFieldList* pTagsList, tFieldList* pFieldList, SSq
static
int32_t
setObjFullName
(
char
*
fullName
,
char
*
account
,
SSQLToken
*
pDB
,
SSQLToken
*
tableName
,
int32_t
*
len
);
static
void
getColumnName
(
tSQLExprItem
*
pItem
,
char
*
resultFieldName
,
int32_t
n
Len
);
static
void
getColumnName
(
tSQLExprItem
*
pItem
,
char
*
resultFieldName
,
int32_t
n
ameLength
);
static
void
getRevisedName
(
char
*
resultFieldName
,
int32_t
functionId
,
int32_t
maxLen
,
char
*
columnName
);
static
int32_t
addExprAndResultField
(
SSqlCmd
*
pCmd
,
int32_t
colIdx
,
tSQLExprItem
*
pItem
);
static
int32_t
insertResultField
(
SSqlCmd
*
pCmd
,
int32_t
fieldIDInResult
,
SColumnList
*
pIdList
,
int16_t
bytes
,
int8_t
type
,
char
*
fieldName
);
static
int32_t
insertResultField
(
SSqlCmd
*
pCmd
,
int32_t
outputIndex
,
SColumnList
*
pIdList
,
int16_t
bytes
,
int8_t
type
,
char
*
fieldName
);
static
int32_t
changeFunctionID
(
int32_t
optr
,
int16_t
*
functionId
);
static
int32_t
parseSelectClause
(
SSqlCmd
*
pCmd
,
tSQLExprList
*
pSelection
,
bool
isMetric
);
static
void
setErrMsg
(
SSqlCmd
*
pCmd
,
const
char
*
pzErrMsg
);
static
bool
validateIpAddress
(
char
*
ip
);
static
bool
hasUnsupportFunctionsForMetricQuery
(
SSqlCmd
*
pCmd
);
static
bool
functionCompatibleCheck
(
SSqlCmd
*
pCmd
);
...
...
@@ -117,6 +115,14 @@ static int32_t tscCheckCreateDbParams(SSqlCmd* pCmd, SCreateDbMsg *pCreate);
static
SColumnList
getColumnList
(
int32_t
num
,
int16_t
tableIndex
,
int32_t
columnIndex
);
/*
* Used during parsing query sql. Since the query sql usually small in length, error position
* is not needed in the final error message.
*/
static
int32_t
invalidSqlErrMsg
(
SSqlCmd
*
pCmd
,
const
char
*
errMsg
)
{
return
tscInvalidSQLErrMsg
(
pCmd
->
payload
,
errMsg
,
NULL
);
}
static
int32_t
tscQueryOnlyMetricTags
(
SSqlCmd
*
pCmd
,
bool
*
queryOnMetricTags
)
{
assert
(
QUERY_IS_STABLE_QUERY
(
pCmd
->
type
));
...
...
@@ -144,13 +150,11 @@ static int setColumnFilterInfoForTimestamp(SSqlCmd* pCmd, tVariant* pVar) {
if
(
seg
!=
NULL
)
{
if
(
taosParseTime
(
pVar
->
pz
,
&
time
,
pVar
->
nLen
,
pMeterMetaInfo
->
pMeterMeta
->
precision
)
!=
TSDB_CODE_SUCCESS
)
{
setErrMsg
(
pCmd
,
msg
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg
);
}
}
else
{
if
(
tVariantDump
(
pVar
,
(
char
*
)
&
time
,
TSDB_DATA_TYPE_BIGINT
))
{
setErrMsg
(
pCmd
,
msg
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg
);
}
}
...
...
@@ -169,8 +173,7 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
SSqlCmd
*
pCmd
=
&
(
pSql
->
cmd
);
if
(
!
pInfo
->
validSql
)
{
setErrMsg
(
pCmd
,
pInfo
->
pzErrMsg
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
pInfo
->
pzErrMsg
);
}
SMeterMetaInfo
*
pMeterMetaInfo
=
tscAddEmptyMeterMetaInfo
(
pCmd
);
...
...
@@ -188,8 +191,7 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
SSQLToken
*
pzName
=
&
pInfo
->
pDCLInfo
->
a
[
0
];
if
((
pInfo
->
sqlType
!=
DROP_DNODE
)
&&
(
tscValidateName
(
pzName
)
!=
TSDB_CODE_SUCCESS
))
{
setErrMsg
(
pCmd
,
msg2
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg2
);
}
if
(
pInfo
->
sqlType
==
DROP_DATABASE
)
{
...
...
@@ -200,7 +202,7 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
int32_t
code
=
setObjFullName
(
pMeterMetaInfo
->
name
,
getAccountId
(
pSql
),
pzName
,
NULL
,
NULL
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
set
ErrMsg
(
pCmd
,
msg2
);
invalidSql
ErrMsg
(
pCmd
,
msg2
);
}
return
code
;
...
...
@@ -212,13 +214,12 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
int32_t
ret
=
setMeterID
(
pSql
,
pzName
,
0
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
set
ErrMsg
(
pCmd
,
msg
);
invalidSql
ErrMsg
(
pCmd
,
msg
);
}
return
ret
;
}
else
{
if
(
pzName
->
n
>
TSDB_USER_LEN
)
{
setErrMsg
(
pCmd
,
msg
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg
);
}
if
(
pInfo
->
sqlType
==
DROP_USER
)
{
...
...
@@ -230,15 +231,13 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
const
int32_t
MAX_IP_ADDRESS_LEGNTH
=
16
;
if
(
pzName
->
n
>
MAX_IP_ADDRESS_LEGNTH
)
{
setErrMsg
(
pCmd
,
msg1
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg1
);
}
char
str
[
128
]
=
{
0
};
strncpy
(
str
,
pzName
->
z
,
pzName
->
n
);
if
(
!
validateIpAddress
(
str
))
{
setErrMsg
(
pCmd
,
msg1
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg1
);
}
}
...
...
@@ -254,14 +253,11 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
SSQLToken
*
pToken
=
&
pInfo
->
pDCLInfo
->
a
[
0
];
if
(
tscValidateName
(
pToken
)
!=
TSDB_CODE_SUCCESS
)
{
const
char
*
msg1
=
"invalid db name"
;
setErrMsg
(
pCmd
,
msg1
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
"invalid db name"
);
}
if
(
pToken
->
n
>
TSDB_DB_NAME_LEN
)
{
setErrMsg
(
pCmd
,
msg
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg
);
}
int32_t
ret
=
setObjFullName
(
pMeterMetaInfo
->
name
,
getAccountId
(
pSql
),
pToken
,
NULL
,
NULL
);
...
...
@@ -310,14 +306,12 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
SCreateDBInfo
*
pCreateDB
=
&
(
pInfo
->
pDCLInfo
->
dbOpt
);
if
(
tscValidateName
(
&
pCreateDB
->
dbname
)
!=
TSDB_CODE_SUCCESS
)
{
setErrMsg
(
pCmd
,
msg3
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg3
);
}
int32_t
ret
=
setObjFullName
(
pMeterMetaInfo
->
name
,
getAccountId
(
pSql
),
&
(
pCreateDB
->
dbname
),
NULL
,
NULL
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
setErrMsg
(
pCmd
,
msg2
);
return
ret
;
return
invalidSqlErrMsg
(
pCmd
,
msg2
);
}
if
(
parseCreateDBOptions
(
pCmd
,
pCreateDB
)
!=
TSDB_CODE_SUCCESS
)
{
...
...
@@ -335,14 +329,12 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
char
ipAddr
[
64
]
=
{
0
};
const
int32_t
MAX_IP_ADDRESS_LENGTH
=
16
;
if
(
pInfo
->
pDCLInfo
->
nTokens
>
1
||
pInfo
->
pDCLInfo
->
a
[
0
].
n
>
MAX_IP_ADDRESS_LENGTH
)
{
setErrMsg
(
pCmd
,
msg
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg
);
}
memcpy
(
ipAddr
,
pInfo
->
pDCLInfo
->
a
[
0
].
z
,
pInfo
->
pDCLInfo
->
a
[
0
].
n
);
if
(
validateIpAddress
(
ipAddr
)
==
false
)
{
setErrMsg
(
pCmd
,
msg
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg
);
}
strncpy
(
pMeterMetaInfo
->
name
,
pInfo
->
pDCLInfo
->
a
[
0
].
z
,
pInfo
->
pDCLInfo
->
a
[
0
].
n
);
...
...
@@ -361,8 +353,7 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
const
char
*
msg4
=
"invalid state option, available options[no, r, w, all]"
;
if
(
pInfo
->
pDCLInfo
->
a
[
1
].
type
!=
TK_STRING
)
{
setErrMsg
(
pCmd
,
msg3
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg3
);
}
strdequote
(
pInfo
->
pDCLInfo
->
a
[
1
].
z
);
...
...
@@ -370,18 +361,15 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
pInfo
->
pDCLInfo
->
a
[
1
].
n
=
strlen
(
pInfo
->
pDCLInfo
->
a
[
1
].
z
);
if
(
pInfo
->
pDCLInfo
->
a
[
1
].
n
<=
0
)
{
setErrMsg
(
pCmd
,
msg1
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg1
);
}
if
(
pInfo
->
pDCLInfo
->
a
[
0
].
n
>
TSDB_USER_LEN
||
pInfo
->
pDCLInfo
->
a
[
1
].
n
>
TSDB_PASSWORD_LEN
)
{
setErrMsg
(
pCmd
,
msg
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg
);
}
if
(
tscValidateName
(
&
pInfo
->
pDCLInfo
->
a
[
0
])
!=
TSDB_CODE_SUCCESS
)
{
setErrMsg
(
pCmd
,
msg2
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg2
);
}
strncpy
(
pMeterMetaInfo
->
name
,
pInfo
->
pDCLInfo
->
a
[
0
].
z
,
pInfo
->
pDCLInfo
->
a
[
0
].
n
);
// name
...
...
@@ -414,8 +402,7 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
}
else
if
(
strncmp
(
pAcctOpt
->
stat
.
z
,
"no"
,
2
)
==
0
&&
pAcctOpt
->
stat
.
n
==
2
)
{
pCmd
->
defaultVal
[
8
]
=
0
;
}
else
{
setErrMsg
(
pCmd
,
msg4
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg4
);
}
}
}
...
...
@@ -434,8 +421,7 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
if
(
num
==
2
)
{
if
(
pInfo
->
pDCLInfo
->
a
[
1
].
type
!=
TK_STRING
)
{
setErrMsg
(
pCmd
,
msg3
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg3
);
}
strdequote
(
pInfo
->
pDCLInfo
->
a
[
1
].
z
);
...
...
@@ -443,26 +429,22 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
pInfo
->
pDCLInfo
->
a
[
1
].
n
=
strlen
(
pInfo
->
pDCLInfo
->
a
[
1
].
z
);
if
(
pInfo
->
pDCLInfo
->
a
[
1
].
n
<=
0
)
{
setErrMsg
(
pCmd
,
msg1
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg1
);
}
if
(
pInfo
->
pDCLInfo
->
a
[
1
].
n
>
TSDB_PASSWORD_LEN
)
{
setErrMsg
(
pCmd
,
msg
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg
);
}
strncpy
(
pCmd
->
payload
,
pInfo
->
pDCLInfo
->
a
[
1
].
z
,
pInfo
->
pDCLInfo
->
a
[
1
].
n
);
// passwd
}
if
(
pInfo
->
pDCLInfo
->
a
[
0
].
n
>
TSDB_USER_LEN
)
{
setErrMsg
(
pCmd
,
msg
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg
);
}
if
(
tscValidateName
(
&
pInfo
->
pDCLInfo
->
a
[
0
])
!=
TSDB_CODE_SUCCESS
)
{
setErrMsg
(
pCmd
,
msg2
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg2
);
}
strncpy
(
pMeterMetaInfo
->
name
,
pInfo
->
pDCLInfo
->
a
[
0
].
z
,
pInfo
->
pDCLInfo
->
a
[
0
].
n
);
// name
...
...
@@ -492,8 +474,7 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
}
else
if
(
strncmp
(
pAcctOpt
->
stat
.
z
,
"no"
,
2
)
==
0
&&
pAcctOpt
->
stat
.
n
==
2
)
{
pCmd
->
defaultVal
[
8
]
=
0
;
}
else
{
setErrMsg
(
pCmd
,
msg4
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg4
);
}
}
break
;
...
...
@@ -503,21 +484,18 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
SSQLToken
*
pToken
=
&
pInfo
->
pDCLInfo
->
a
[
0
];
const
char
*
msg
=
"table name is too long"
;
const
char
*
msg1
=
"invalid table name"
;
if
(
tscValidateName
(
pToken
)
!=
TSDB_CODE_SUCCESS
)
{
const
char
*
msg1
=
"invalid table name"
;
setErrMsg
(
pCmd
,
msg1
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg1
);
}
if
(
pToken
->
n
>
TSDB_METER_NAME_LEN
)
{
setErrMsg
(
pCmd
,
msg
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg
);
}
if
(
setMeterID
(
pSql
,
pToken
,
0
)
!=
TSDB_CODE_SUCCESS
)
{
setErrMsg
(
pCmd
,
msg
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg
);
}
int32_t
ret
=
tscGetMeterMeta
(
pSql
,
pMeterMetaInfo
->
name
,
0
);
...
...
@@ -546,13 +524,11 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
}
if
(
pDCL
->
a
[
1
].
n
<=
0
)
{
setErrMsg
(
pCmd
,
msg3
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg3
);
}
if
(
pDCL
->
a
[
0
].
n
>
TSDB_METER_NAME_LEN
||
pDCL
->
a
[
1
].
n
>
TSDB_PASSWORD_LEN
)
{
setErrMsg
(
pCmd
,
msg
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg
);
}
if
(
pCmd
->
command
==
TSDB_SQL_CFG_DNODE
)
{
...
...
@@ -561,16 +537,14 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
/* validate the ip address */
if
(
!
validateIpAddress
(
ip
))
{
setErrMsg
(
pCmd
,
msg1
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg1
);
}
strcpy
(
pMeterMetaInfo
->
name
,
ip
);
/* validate the parameter names and options */
if
(
validateDNodeConfig
(
pDCL
)
!=
TSDB_CODE_SUCCESS
)
{
setErrMsg
(
pCmd
,
msg2
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg2
);
}
strncpy
(
pCmd
->
payload
,
pDCL
->
a
[
1
].
z
,
pDCL
->
a
[
1
].
n
);
...
...
@@ -594,8 +568,7 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
if
(
pDCL
->
a
[
1
].
n
<=
0
||
pInfo
->
pDCLInfo
->
a
[
1
].
n
>
TSDB_PASSWORD_LEN
)
{
/* password cannot be empty string */
setErrMsg
(
pCmd
,
msg1
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg1
);
}
strncpy
(
pCmd
->
payload
,
pDCL
->
a
[
1
].
z
,
pDCL
->
a
[
1
].
n
);
...
...
@@ -609,8 +582,7 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
}
else
if
(
strncasecmp
(
pDCL
->
a
[
1
].
z
,
"write"
,
5
)
==
0
&&
pDCL
->
a
[
1
].
n
==
5
)
{
pCmd
->
count
=
3
;
}
else
{
setErrMsg
(
pCmd
,
msg
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg
);
}
}
else
{
return
TSDB_CODE_INVALID_SQL
;
...
...
@@ -620,19 +592,12 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
}
case
ALTER_LOCAL
:
{
pCmd
->
command
=
TSDB_SQL_CFG_LOCAL
;
/*
if (pInfo->pDCLInfo->a[0].n > TSDB_METER_ID_LEN) {
setErrMsg(pCmd, msg);
return TSDB_CODE_INVALID_SQL;
}
*/
tDCLSQL
*
pDCL
=
pInfo
->
pDCLInfo
;
const
char
*
msg
=
"invalid configure options or values"
;
// validate the parameter names and options
if
(
validateLocalConfig
(
pDCL
)
!=
TSDB_CODE_SUCCESS
)
{
setErrMsg
(
pCmd
,
msg
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg
);
}
strncpy
(
pCmd
->
payload
,
pDCL
->
a
[
0
].
z
,
pDCL
->
a
[
0
].
n
);
...
...
@@ -659,13 +624,11 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
SSQLToken
*
pzTableName
=
&
(
pInfo
->
pCreateTableInfo
->
name
);
if
(
tscValidateName
(
pzTableName
)
!=
TSDB_CODE_SUCCESS
)
{
setErrMsg
(
pCmd
,
msg1
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg1
);
}
if
(
setMeterID
(
pSql
,
pzTableName
,
0
)
!=
TSDB_CODE_SUCCESS
)
{
setErrMsg
(
pCmd
,
msg
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg
);
}
if
(
!
validateTableColumnInfo
(
pFieldList
,
pCmd
)
||
...
...
@@ -695,19 +658,18 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
const
char
*
msg
=
"invalid table name"
;
const
char
*
msg1
=
"illegal value or data overflow"
;
const
char
*
msg2
=
"illegal number of tags"
;
const
char
*
msg3
=
"tag value too long"
;
// table name
// metric name, create table by using dst
SSQLToken
*
pToken
=
&
(
pInfo
->
pCreateTableInfo
->
usingInfo
.
metricName
);
if
(
tscValidateName
(
pToken
)
!=
TSDB_CODE_SUCCESS
)
{
setErrMsg
(
pCmd
,
msg
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg
);
}
if
(
setMeterID
(
pSql
,
pToken
,
0
)
!=
TSDB_CODE_SUCCESS
)
{
setErrMsg
(
pCmd
,
msg
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg
);
}
// get meter meta from mnode
...
...
@@ -722,8 +684,7 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
}
if
(
pMeterMetaInfo
->
pMeterMeta
->
numOfTags
!=
pList
->
nExpr
)
{
setErrMsg
(
pCmd
,
msg2
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg2
);
}
// too long tag values will return invalid sql, not be truncated automatically
...
...
@@ -733,24 +694,20 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
for
(
int32_t
i
=
0
;
i
<
pList
->
nExpr
;
++
i
)
{
int32_t
ret
=
tVariantDump
(
&
(
pList
->
a
[
i
].
pVar
),
tagVal
,
pTagSchema
[
i
].
type
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
setErrMsg
(
pCmd
,
msg1
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg1
);
}
// validate the length of binary
if
((
pTagSchema
[
i
].
type
==
TSDB_DATA_TYPE_BINARY
||
pTagSchema
[
i
].
type
==
TSDB_DATA_TYPE_NCHAR
)
&&
pList
->
a
[
i
].
pVar
.
nLen
>
pTagSchema
[
i
].
bytes
)
{
const
char
*
msg3
=
"tag value too long"
;
setErrMsg
(
pCmd
,
msg3
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg3
);
}
tagVal
+=
pTagSchema
[
i
].
bytes
;
}
if
(
tscValidateName
(
&
pInfo
->
pCreateTableInfo
->
name
)
!=
TSDB_CODE_SUCCESS
)
{
setErrMsg
(
pCmd
,
msg
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg
);
}
int32_t
ret
=
setMeterID
(
pSql
,
&
pInfo
->
pCreateTableInfo
->
name
,
0
);
...
...
@@ -768,14 +725,14 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
const
char
*
msg2
=
"table name too long"
;
const
char
*
msg3
=
"fill only available for interval query"
;
const
char
*
msg4
=
"fill option not supported in stream computing"
;
const
char
*
msg5
=
"sql too long"
;
// todo ADD support
// if sql specifies db, use it, otherwise use default db
SSQLToken
*
pzTableName
=
&
(
pInfo
->
pCreateTableInfo
->
name
);
SQuerySQL
*
pQuerySql
=
pInfo
->
pCreateTableInfo
->
pSelect
;
if
(
tscValidateName
(
pzTableName
)
!=
TSDB_CODE_SUCCESS
)
{
setErrMsg
(
pCmd
,
msg1
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg1
);
}
tVariantList
*
pSrcMeterName
=
pInfo
->
pCreateTableInfo
->
pSelect
->
from
;
...
...
@@ -783,13 +740,11 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
SSQLToken
srcToken
=
{.
z
=
pVar
->
pz
,
.
n
=
pVar
->
nLen
,
.
type
=
TK_STRING
};
if
(
tscValidateName
(
&
srcToken
)
!=
TSDB_CODE_SUCCESS
)
{
setErrMsg
(
pCmd
,
msg1
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg1
);
}
if
(
setMeterID
(
pSql
,
&
srcToken
,
0
)
!=
TSDB_CODE_SUCCESS
)
{
setErrMsg
(
pCmd
,
msg2
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg2
);
}
int32_t
code
=
tscGetMeterMeta
(
pSql
,
pMeterMetaInfo
->
name
,
0
);
...
...
@@ -823,23 +778,19 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
// set the created table[stream] name
if
(
setMeterID
(
pSql
,
pzTableName
,
0
)
!=
TSDB_CODE_SUCCESS
)
{
setErrMsg
(
pCmd
,
msg1
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg1
);
}
// copy sql length
int
ret
=
tscAllocPayload
(
pCmd
,
pQuerySql
->
selectToken
.
n
+
8
);
if
(
TSDB_CODE_SUCCESS
!=
ret
)
{
const
char
*
msg6
=
"client out of memory"
;
setErrMsg
(
pCmd
,
msg6
);
invalidSqlErrMsg
(
pCmd
,
"client out of memory"
);
return
ret
;
}
strncpy
(
pCmd
->
payload
,
pQuerySql
->
selectToken
.
z
,
pQuerySql
->
selectToken
.
n
);
if
(
pQuerySql
->
selectToken
.
n
>
TSDB_MAX_SAVED_SQL_LEN
)
{
const
char
*
msg5
=
"sql too long"
;
// todo ADD support
setErrMsg
(
pCmd
,
msg5
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg5
);
}
if
(
tsRewriteFieldNameIfNecessary
(
pCmd
)
!=
TSDB_CODE_SUCCESS
)
{
...
...
@@ -858,16 +809,14 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
*/
if
(
pQuerySql
->
fillType
!=
NULL
)
{
if
(
pCmd
->
nAggTimeInterval
==
0
)
{
setErrMsg
(
pCmd
,
msg3
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg3
);
}
tVariantListItem
*
pItem
=
&
pQuerySql
->
fillType
->
a
[
0
];
if
(
pItem
->
pVar
.
nType
==
TSDB_DATA_TYPE_BINARY
)
{
if
(
!
((
strncmp
(
pItem
->
pVar
.
pz
,
"none"
,
4
)
==
0
&&
pItem
->
pVar
.
nLen
==
4
)
||
(
strncmp
(
pItem
->
pVar
.
pz
,
"null"
,
4
)
==
0
&&
pItem
->
pVar
.
nLen
==
4
)))
{
setErrMsg
(
pCmd
,
msg4
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg4
);
}
}
}
...
...
@@ -890,10 +839,11 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
const
char
*
msg8
=
"too many columns in selection clause"
;
const
char
*
msg9
=
"TWA query requires both the start and end time"
;
int32_t
code
=
TSDB_CODE_SUCCESS
;
// too many result columns not support order by in query
if
(
pQuerySql
->
pSelection
->
nExpr
>
TSDB_MAX_COLUMNS
)
{
setErrMsg
(
pCmd
,
msg8
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg8
);
}
/*
...
...
@@ -910,8 +860,7 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
}
if
(
pQuerySql
->
from
->
nExpr
>
TSDB_MAX_JOIN_TABLE_NUM
)
{
setErrMsg
(
pCmd
,
msg7
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg7
);
}
// set all query tables, which are maybe more than one.
...
...
@@ -919,16 +868,14 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
tVariant
*
pTableItem
=
&
pQuerySql
->
from
->
a
[
i
].
pVar
;
if
(
pTableItem
->
nType
!=
TSDB_DATA_TYPE_BINARY
)
{
setErrMsg
(
pCmd
,
msg0
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg0
);
}
pTableItem
->
nLen
=
strdequote
(
pTableItem
->
pz
);
SSQLToken
tableName
=
{.
z
=
pTableItem
->
pz
,
.
n
=
pTableItem
->
nLen
,
.
type
=
TK_STRING
};
if
(
tscValidateName
(
&
tableName
)
!=
TSDB_CODE_SUCCESS
)
{
setErrMsg
(
pCmd
,
msg0
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg0
);
}
if
(
pCmd
->
numOfTables
<=
i
)
{
...
...
@@ -937,19 +884,17 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
SSQLToken
t
=
{.
type
=
TSDB_DATA_TYPE_BINARY
,
.
n
=
pTableItem
->
nLen
,
.
z
=
pTableItem
->
pz
};
if
(
setMeterID
(
pSql
,
&
t
,
i
)
!=
TSDB_CODE_SUCCESS
)
{
setErrMsg
(
pCmd
,
msg1
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg1
);
}
SMeterMetaInfo
*
pMeterInfo1
=
tscGetMeterMetaInfo
(
pCmd
,
i
);
int32_t
code
=
tscGetMeterMeta
(
pSql
,
pMeterInfo1
->
name
,
i
);
code
=
tscGetMeterMeta
(
pSql
,
pMeterInfo1
->
name
,
i
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
return
code
;
}
}
pSql
->
cmd
.
command
=
TSDB_SQL_SELECT
;
int32_t
code
=
TSDB_CODE_SUCCESS
;
// parse the group by clause in the first place
if
(
parseGroupbyClause
(
pCmd
,
pQuerySql
->
pGroupby
)
!=
TSDB_CODE_SUCCESS
)
{
...
...
@@ -976,8 +921,7 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
// TODO refactor pCmd->count == 1 means sql in stream function
if
(
!
tscEmbedded
&&
pCmd
->
count
==
0
)
{
const
char
*
msg
=
"not support sliding in query"
;
setErrMsg
(
pCmd
,
msg
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg
);
}
getTimestampInUsFromStr
(
pSliding
->
z
,
pSliding
->
n
,
&
pCmd
->
nSlidingTime
);
...
...
@@ -986,13 +930,11 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
}
if
(
pCmd
->
nSlidingTime
<
tsMinSlidingTime
)
{
setErrMsg
(
pCmd
,
msg3
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg3
);
}
if
(
pCmd
->
nSlidingTime
>
pCmd
->
nAggTimeInterval
)
{
setErrMsg
(
pCmd
,
msg4
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg4
);
}
}
...
...
@@ -1023,8 +965,7 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
if
((
pCmd
->
stime
==
0
||
pCmd
->
etime
==
INT64_MAX
||
(
pCmd
->
etime
==
INT64_MAX
/
1000
&&
pMeterMetaInfo
->
pMeterMeta
->
precision
==
TSDB_TIME_PRECISION_MILLI
))
&&
tscIsTWAQuery
(
pCmd
))
{
setErrMsg
(
pCmd
,
msg9
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg9
);
}
// no result due to invalid query time range
...
...
@@ -1034,22 +975,19 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
}
if
(
!
hasTimestampForPointInterpQuery
(
pCmd
))
{
setErrMsg
(
pCmd
,
msg2
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg2
);
}
if
(
pQuerySql
->
fillType
!=
NULL
)
{
if
(
pCmd
->
nAggTimeInterval
==
0
&&
(
!
tscIsPointInterpQuery
(
pCmd
)))
{
setErrMsg
(
pCmd
,
msg5
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg5
);
}
if
(
pCmd
->
nAggTimeInterval
>
0
)
{
int64_t
timeRange
=
labs
(
pCmd
->
stime
-
pCmd
->
etime
);
// number of result is not greater than 10,000,000
if
((
timeRange
==
0
)
||
(
timeRange
/
pCmd
->
nAggTimeInterval
)
>
MAX_RETRIEVE_ROWS_IN_INTERVAL_QUERY
)
{
setErrMsg
(
pCmd
,
msg6
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg6
);
}
}
...
...
@@ -1064,8 +1002,7 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
int64_t
timeRange
=
labs
(
pCmd
->
stime
-
pCmd
->
etime
);
if
(
timeRange
==
0
&&
pCmd
->
stime
==
0
)
{
setErrMsg
(
pCmd
,
msg6
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg6
);
}
}
...
...
@@ -1153,8 +1090,7 @@ int32_t parseIntervalClause(SSqlCmd* pCmd, SQuerySQL* pQuerySql) {
// interval cannot be less than 10 milliseconds
if
(
pCmd
->
nAggTimeInterval
<
tsMinIntervalTime
)
{
setErrMsg
(
pCmd
,
msg2
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg2
);
}
// for top/bottom + interval query, we do not add additional timestamp column in the front
...
...
@@ -1166,8 +1102,7 @@ int32_t parseIntervalClause(SSqlCmd* pCmd, SQuerySQL* pQuerySql) {
for
(
int32_t
i
=
0
;
i
<
pCmd
->
fieldsInfo
.
numOfOutputCols
;
++
i
)
{
SSqlExpr
*
pExpr
=
tscSqlExprGet
(
pCmd
,
i
);
if
(
pExpr
->
functionId
==
TSDB_FUNC_COUNT
&&
TSDB_COL_IS_TAG
(
pExpr
->
colInfo
.
flag
))
{
setErrMsg
(
pCmd
,
msg1
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg1
);
}
}
...
...
@@ -1210,13 +1145,11 @@ int32_t setSlidingClause(SSqlCmd* pCmd, SQuerySQL* pQuerySql) {
}
if
(
pCmd
->
nSlidingTime
<
tsMinSlidingTime
)
{
setErrMsg
(
pCmd
,
msg0
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg0
);
}
if
(
pCmd
->
nSlidingTime
>
pCmd
->
nAggTimeInterval
)
{
setErrMsg
(
pCmd
,
msg1
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg1
);
}
}
...
...
@@ -1244,7 +1177,7 @@ int32_t setMeterID(SSqlObj* pSql, SSQLToken* pzTableName, int32_t tableIndex) {
}
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
set
ErrMsg
(
pCmd
,
msg
);
invalidSql
ErrMsg
(
pCmd
,
msg
);
}
return
code
;
...
...
@@ -1263,13 +1196,13 @@ static bool validateTableColumnInfo(tFieldList* pFieldList, SSqlCmd* pCmd) {
// number of fields no less than 2
if
(
pFieldList
->
nField
<=
1
||
pFieldList
->
nField
>
TSDB_MAX_COLUMNS
)
{
set
ErrMsg
(
pCmd
,
msg
);
invalidSql
ErrMsg
(
pCmd
,
msg
);
return
false
;
}
// first column must be timestamp
if
(
pFieldList
->
p
[
0
].
type
!=
TSDB_DATA_TYPE_TIMESTAMP
)
{
set
ErrMsg
(
pCmd
,
msg1
);
invalidSql
ErrMsg
(
pCmd
,
msg1
);
return
false
;
}
...
...
@@ -1280,7 +1213,7 @@ static bool validateTableColumnInfo(tFieldList* pFieldList, SSqlCmd* pCmd) {
// max row length must be less than TSDB_MAX_BYTES_PER_ROW
if
(
nLen
>
TSDB_MAX_BYTES_PER_ROW
)
{
set
ErrMsg
(
pCmd
,
msg2
);
invalidSql
ErrMsg
(
pCmd
,
msg2
);
return
false
;
}
...
...
@@ -1288,23 +1221,23 @@ static bool validateTableColumnInfo(tFieldList* pFieldList, SSqlCmd* pCmd) {
for
(
int32_t
i
=
0
;
i
<
pFieldList
->
nField
;
++
i
)
{
TAOS_FIELD
*
pField
=
&
pFieldList
->
p
[
i
];
if
(
pField
->
type
<
TSDB_DATA_TYPE_BOOL
||
pField
->
type
>
TSDB_DATA_TYPE_NCHAR
)
{
set
ErrMsg
(
pCmd
,
msg4
);
invalidSql
ErrMsg
(
pCmd
,
msg4
);
return
false
;
}
if
((
pField
->
type
==
TSDB_DATA_TYPE_BINARY
&&
(
pField
->
bytes
<=
0
||
pField
->
bytes
>
TSDB_MAX_BINARY_LEN
))
||
(
pField
->
type
==
TSDB_DATA_TYPE_NCHAR
&&
(
pField
->
bytes
<=
0
||
pField
->
bytes
>
TSDB_MAX_NCHAR_LEN
)))
{
set
ErrMsg
(
pCmd
,
msg5
);
invalidSql
ErrMsg
(
pCmd
,
msg5
);
return
false
;
}
if
(
validateColumnName
(
pField
->
name
)
!=
TSDB_CODE_SUCCESS
)
{
set
ErrMsg
(
pCmd
,
msg6
);
invalidSql
ErrMsg
(
pCmd
,
msg6
);
return
false
;
}
if
(
has
(
pFieldList
,
i
+
1
,
pFieldList
->
p
[
i
].
name
)
==
true
)
{
set
ErrMsg
(
pCmd
,
msg3
);
invalidSql
ErrMsg
(
pCmd
,
msg3
);
return
false
;
}
}
...
...
@@ -1325,7 +1258,7 @@ static bool validateTagParams(tFieldList* pTagsList, tFieldList* pFieldList, SSq
// number of fields at least 1
if
(
pTagsList
->
nField
<
1
||
pTagsList
->
nField
>
TSDB_MAX_TAGS
)
{
set
ErrMsg
(
pCmd
,
msg1
);
invalidSql
ErrMsg
(
pCmd
,
msg1
);
return
false
;
}
...
...
@@ -1336,14 +1269,14 @@ static bool validateTagParams(tFieldList* pTagsList, tFieldList* pFieldList, SSq
// max tag row length must be less than TSDB_MAX_TAGS_LEN
if
(
nLen
>
TSDB_MAX_TAGS_LEN
)
{
set
ErrMsg
(
pCmd
,
msg2
);
invalidSql
ErrMsg
(
pCmd
,
msg2
);
return
false
;
}
// field name must be unique
for
(
int32_t
i
=
0
;
i
<
pTagsList
->
nField
;
++
i
)
{
if
(
has
(
pFieldList
,
0
,
pTagsList
->
p
[
i
].
name
)
==
true
)
{
set
ErrMsg
(
pCmd
,
msg3
);
invalidSql
ErrMsg
(
pCmd
,
msg3
);
return
false
;
}
}
...
...
@@ -1351,28 +1284,28 @@ static bool validateTagParams(tFieldList* pTagsList, tFieldList* pFieldList, SSq
/* timestamp in tag is not allowed */
for
(
int32_t
i
=
0
;
i
<
pTagsList
->
nField
;
++
i
)
{
if
(
pTagsList
->
p
[
i
].
type
==
TSDB_DATA_TYPE_TIMESTAMP
)
{
set
ErrMsg
(
pCmd
,
msg4
);
invalidSql
ErrMsg
(
pCmd
,
msg4
);
return
false
;
}
if
(
pTagsList
->
p
[
i
].
type
<
TSDB_DATA_TYPE_BOOL
||
pTagsList
->
p
[
i
].
type
>
TSDB_DATA_TYPE_NCHAR
)
{
set
ErrMsg
(
pCmd
,
msg5
);
invalidSql
ErrMsg
(
pCmd
,
msg5
);
return
false
;
}
if
((
pTagsList
->
p
[
i
].
type
==
TSDB_DATA_TYPE_BINARY
&&
pTagsList
->
p
[
i
].
bytes
<=
0
)
||
(
pTagsList
->
p
[
i
].
type
==
TSDB_DATA_TYPE_NCHAR
&&
pTagsList
->
p
[
i
].
bytes
<=
0
))
{
set
ErrMsg
(
pCmd
,
msg7
);
invalidSql
ErrMsg
(
pCmd
,
msg7
);
return
false
;
}
if
(
validateColumnName
(
pTagsList
->
p
[
i
].
name
)
!=
TSDB_CODE_SUCCESS
)
{
set
ErrMsg
(
pCmd
,
msg6
);
invalidSql
ErrMsg
(
pCmd
,
msg6
);
return
false
;
}
if
(
has
(
pTagsList
,
i
+
1
,
pTagsList
->
p
[
i
].
name
)
==
true
)
{
set
ErrMsg
(
pCmd
,
msg3
);
invalidSql
ErrMsg
(
pCmd
,
msg3
);
return
false
;
}
}
...
...
@@ -1399,18 +1332,18 @@ bool validateOneTags(SSqlCmd* pCmd, TAOS_FIELD* pTagField) {
char
msg
[
128
]
=
{
0
};
sprintf
(
msg
,
"tags no more than %d"
,
TSDB_MAX_TAGS
);
set
ErrMsg
(
pCmd
,
msg
);
invalidSql
ErrMsg
(
pCmd
,
msg
);
return
false
;
}
// no timestamp allowable
if
(
pTagField
->
type
==
TSDB_DATA_TYPE_TIMESTAMP
)
{
set
ErrMsg
(
pCmd
,
msg1
);
invalidSql
ErrMsg
(
pCmd
,
msg1
);
return
false
;
}
if
(
pTagField
->
type
<
TSDB_DATA_TYPE_BOOL
&&
pTagField
->
type
>
TSDB_DATA_TYPE_NCHAR
)
{
set
ErrMsg
(
pCmd
,
msg6
);
invalidSql
ErrMsg
(
pCmd
,
msg6
);
return
false
;
}
...
...
@@ -1423,19 +1356,19 @@ bool validateOneTags(SSqlCmd* pCmd, TAOS_FIELD* pTagField) {
// length less than TSDB_MAX_TASG_LEN
if
(
nLen
+
pTagField
->
bytes
>
TSDB_MAX_TAGS_LEN
)
{
set
ErrMsg
(
pCmd
,
msg3
);
invalidSql
ErrMsg
(
pCmd
,
msg3
);
return
false
;
}
// tags name can not be a keyword
if
(
validateColumnName
(
pTagField
->
name
)
!=
TSDB_CODE_SUCCESS
)
{
set
ErrMsg
(
pCmd
,
msg4
);
invalidSql
ErrMsg
(
pCmd
,
msg4
);
return
false
;
}
// binary(val), val can not be equalled to or less than 0
if
((
pTagField
->
type
==
TSDB_DATA_TYPE_BINARY
||
pTagField
->
type
==
TSDB_DATA_TYPE_NCHAR
)
&&
pTagField
->
bytes
<=
0
)
{
set
ErrMsg
(
pCmd
,
msg5
);
invalidSql
ErrMsg
(
pCmd
,
msg5
);
return
false
;
}
...
...
@@ -1444,7 +1377,7 @@ bool validateOneTags(SSqlCmd* pCmd, TAOS_FIELD* pTagField) {
for
(
int32_t
i
=
0
;
i
<
pMeterMeta
->
numOfTags
+
pMeterMeta
->
numOfColumns
;
++
i
)
{
if
(
strncasecmp
(
pTagField
->
name
,
pSchema
[
i
].
name
,
TSDB_COL_NAME_LEN
)
==
0
)
{
set
ErrMsg
(
pCmd
,
msg2
);
invalidSql
ErrMsg
(
pCmd
,
msg2
);
return
false
;
}
}
...
...
@@ -1466,17 +1399,17 @@ bool validateOneColumn(SSqlCmd* pCmd, TAOS_FIELD* pColField) {
// no more max columns
if
(
pMeterMeta
->
numOfColumns
>=
TSDB_MAX_COLUMNS
||
pMeterMeta
->
numOfTags
+
pMeterMeta
->
numOfColumns
>=
TSDB_MAX_COLUMNS
)
{
set
ErrMsg
(
pCmd
,
msg1
);
invalidSql
ErrMsg
(
pCmd
,
msg1
);
return
false
;
}
if
(
pColField
->
type
<
TSDB_DATA_TYPE_BOOL
||
pColField
->
type
>
TSDB_DATA_TYPE_NCHAR
)
{
set
ErrMsg
(
pCmd
,
msg4
);
invalidSql
ErrMsg
(
pCmd
,
msg4
);
return
false
;
}
if
(
validateColumnName
(
pColField
->
name
)
!=
TSDB_CODE_SUCCESS
)
{
set
ErrMsg
(
pCmd
,
msg5
);
invalidSql
ErrMsg
(
pCmd
,
msg5
);
return
false
;
}
...
...
@@ -1488,20 +1421,20 @@ bool validateOneColumn(SSqlCmd* pCmd, TAOS_FIELD* pColField) {
}
if
(
pColField
->
bytes
<=
0
)
{
set
ErrMsg
(
pCmd
,
msg6
);
invalidSql
ErrMsg
(
pCmd
,
msg6
);
return
false
;
}
// length less than TSDB_MAX_BYTES_PER_ROW
if
(
nLen
+
pColField
->
bytes
>
TSDB_MAX_BYTES_PER_ROW
)
{
set
ErrMsg
(
pCmd
,
msg3
);
invalidSql
ErrMsg
(
pCmd
,
msg3
);
return
false
;
}
// field name must be unique
for
(
int32_t
i
=
0
;
i
<
pMeterMeta
->
numOfTags
+
pMeterMeta
->
numOfColumns
;
++
i
)
{
if
(
strncasecmp
(
pColField
->
name
,
pSchema
[
i
].
name
,
TSDB_COL_NAME_LEN
)
==
0
)
{
set
ErrMsg
(
pCmd
,
msg2
);
invalidSql
ErrMsg
(
pCmd
,
msg2
);
return
false
;
}
}
...
...
@@ -1642,8 +1575,7 @@ int32_t parseSelectClause(SSqlCmd* pCmd, tSQLExprList* pSelection, bool isMetric
int32_t
ret
=
validateArithmeticSQLExpr
(
pItem
->
pNode
,
pSchema
,
pMeterMetaInfo
->
pMeterMeta
->
numOfColumns
,
&
columnList
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
setErrMsg
(
pCmd
,
msg1
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg1
);
}
char
arithmeticExprStr
[
1024
]
=
{
0
};
...
...
@@ -1672,8 +1604,7 @@ int32_t parseSelectClause(SSqlCmd* pCmd, tSQLExprList* pSelection, bool isMetric
* not support such expression
* e.g., select 12+5 from table_name
*/
setErrMsg
(
pCmd
,
msg3
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg3
);
}
if
(
pCmd
->
fieldsInfo
.
numOfOutputCols
>
TSDB_MAX_COLUMNS
)
{
...
...
@@ -1682,8 +1613,7 @@ int32_t parseSelectClause(SSqlCmd* pCmd, tSQLExprList* pSelection, bool isMetric
}
if
(
!
functionCompatibleCheck
(
pCmd
))
{
setErrMsg
(
pCmd
,
msg2
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg2
);
}
if
(
isMetric
)
{
...
...
@@ -1861,8 +1791,7 @@ int32_t addProjectionExprAndResultField(SSqlCmd* pCmd, tSQLExprItem* pItem) {
SColumnIndex
index
=
COLUMN_INDEX_INITIALIZER
;
if
(
getColumnIndexByNameEx
(
&
pItem
->
pNode
->
colInfo
,
pCmd
,
&
index
)
!=
TSDB_CODE_SUCCESS
)
{
setErrMsg
(
pCmd
,
msg0
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg0
);
}
if
(
index
.
columnIndex
==
TSDB_TBNAME_COLUMN_INDEX
)
{
...
...
@@ -1877,8 +1806,7 @@ int32_t addProjectionExprAndResultField(SSqlCmd* pCmd, tSQLExprItem* pItem) {
SMeterMeta
*
pMeterMeta
=
pMeterMetaInfo
->
pMeterMeta
;
if
(
index
.
columnIndex
>=
pMeterMeta
->
numOfColumns
&&
UTIL_METER_IS_NOMRAL_METER
(
pMeterMetaInfo
))
{
setErrMsg
(
pCmd
,
msg1
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg1
);
}
addProjectQueryCol
(
pCmd
,
startPos
,
&
index
,
pItem
);
...
...
@@ -1902,7 +1830,7 @@ static int32_t setExprInfoForFunctions(SSqlCmd* pCmd, SSchema* pSchema, int32_t
if
(
pSchema
[
pColIndex
->
columnIndex
].
type
==
TSDB_DATA_TYPE_BINARY
||
pSchema
[
pColIndex
->
columnIndex
].
type
==
TSDB_DATA_TYPE_NCHAR
||
pSchema
[
pColIndex
->
columnIndex
].
type
==
TSDB_DATA_TYPE_BOOL
)
{
set
ErrMsg
(
pCmd
,
msg1
);
invalidSql
ErrMsg
(
pCmd
,
msg1
);
return
-
1
;
}
else
{
type
=
TSDB_DATA_TYPE_DOUBLE
;
...
...
@@ -1950,8 +1878,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, int32_t colIdx, tSQLExprItem* pItem
case
TK_COUNT
:
{
if
(
pItem
->
pNode
->
pParam
!=
NULL
&&
pItem
->
pNode
->
pParam
->
nExpr
!=
1
)
{
/* more than one parameter for count() function */
setErrMsg
(
pCmd
,
msg2
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg2
);
}
int16_t
functionID
=
0
;
...
...
@@ -1964,8 +1891,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, int32_t colIdx, tSQLExprItem* pItem
if
(
pItem
->
pNode
->
pParam
!=
NULL
)
{
SSQLToken
*
pToken
=
&
pItem
->
pNode
->
pParam
->
a
[
0
].
pNode
->
colInfo
;
if
(
pToken
->
z
==
NULL
||
pToken
->
n
==
0
)
{
setErrMsg
(
pCmd
,
msg3
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg3
);
}
tSQLExprItem
*
pParamElem
=
&
pItem
->
pNode
->
pParam
->
a
[
0
];
...
...
@@ -1975,8 +1901,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, int32_t colIdx, tSQLExprItem* pItem
SSQLToken
tmpToken
=
pParamElem
->
pNode
->
colInfo
;
if
(
getTableIndexByName
(
&
tmpToken
,
pCmd
,
&
index
)
!=
TSDB_CODE_SUCCESS
)
{
setErrMsg
(
pCmd
,
msg4
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg4
);
}
index
=
(
SColumnIndex
){
0
,
PRIMARYKEY_TIMESTAMP_COL_INDEX
};
...
...
@@ -1985,8 +1910,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, int32_t colIdx, tSQLExprItem* pItem
}
else
{
// count the number of meters created according to the metric
if
(
getColumnIndexByNameEx
(
pToken
,
pCmd
,
&
index
)
!=
TSDB_CODE_SUCCESS
)
{
setErrMsg
(
pCmd
,
msg3
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg3
);
}
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
pCmd
,
index
.
tableIndex
);
...
...
@@ -2027,20 +1951,17 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, int32_t colIdx, tSQLExprItem* pItem
if
(
pItem
->
pNode
->
pParam
==
NULL
||
(
optr
!=
TK_LEASTSQUARES
&&
pItem
->
pNode
->
pParam
->
nExpr
!=
1
)
||
(
optr
==
TK_LEASTSQUARES
&&
pItem
->
pNode
->
pParam
->
nExpr
!=
3
))
{
/* no parameters or more than one parameter for function */
setErrMsg
(
pCmd
,
msg2
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg2
);
}
tSQLExprItem
*
pParamElem
=
&
(
pItem
->
pNode
->
pParam
->
a
[
0
]);
if
(
pParamElem
->
pNode
->
nSQLOptr
!=
TK_ALL
&&
pParamElem
->
pNode
->
nSQLOptr
!=
TK_ID
)
{
setErrMsg
(
pCmd
,
msg2
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg2
);
}
SColumnIndex
index
=
COLUMN_INDEX_INITIALIZER
;
if
(
getColumnIndexByNameEx
(
&
pParamElem
->
pNode
->
colInfo
,
pCmd
,
&
index
)
!=
TSDB_CODE_SUCCESS
)
{
setErrMsg
(
pCmd
,
msg3
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg3
);
}
// 2. check if sql function can be applied on this column data type
...
...
@@ -2049,8 +1970,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, int32_t colIdx, tSQLExprItem* pItem
int16_t
colType
=
pSchema
->
type
;
if
(
colType
==
TSDB_DATA_TYPE_BOOL
||
colType
>=
TSDB_DATA_TYPE_BINARY
)
{
setErrMsg
(
pCmd
,
msg1
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg1
);
}
char
columnName
[
TSDB_COL_NAME_LEN
]
=
{
0
};
...
...
@@ -2082,8 +2002,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, int32_t colIdx, tSQLExprItem* pItem
// functions can not be applied to tags
if
(
index
.
columnIndex
>=
pMeterMetaInfo
->
pMeterMeta
->
numOfColumns
)
{
setErrMsg
(
pCmd
,
msg6
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg6
);
}
SSqlExpr
*
pExpr
=
tscSqlExprInsert
(
pCmd
,
colIdx
,
functionID
,
&
index
,
resultType
,
resultSize
,
resultSize
);
...
...
@@ -2125,8 +2044,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, int32_t colIdx, tSQLExprItem* pItem
if
(
!
requireAllFields
)
{
if
(
pItem
->
pNode
->
pParam
->
nExpr
<
1
)
{
setErrMsg
(
pCmd
,
msg3
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg3
);
}
/* in first/last function, multiple columns can be add to resultset */
...
...
@@ -2134,8 +2052,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, int32_t colIdx, tSQLExprItem* pItem
for
(
int32_t
i
=
0
;
i
<
pItem
->
pNode
->
pParam
->
nExpr
;
++
i
)
{
tSQLExprItem
*
pParamElem
=
&
(
pItem
->
pNode
->
pParam
->
a
[
i
]);
if
(
pParamElem
->
pNode
->
nSQLOptr
!=
TK_ALL
&&
pParamElem
->
pNode
->
nSQLOptr
!=
TK_ID
)
{
setErrMsg
(
pCmd
,
msg3
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg3
);
}
SColumnIndex
index
=
COLUMN_INDEX_INITIALIZER
;
...
...
@@ -2145,8 +2062,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, int32_t colIdx, tSQLExprItem* pItem
SSQLToken
tmpToken
=
pParamElem
->
pNode
->
colInfo
;
if
(
getTableIndexByName
(
&
tmpToken
,
pCmd
,
&
index
)
!=
TSDB_CODE_SUCCESS
)
{
setErrMsg
(
pCmd
,
msg4
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg4
);
}
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
pCmd
,
index
.
tableIndex
);
...
...
@@ -2161,8 +2077,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, int32_t colIdx, tSQLExprItem* pItem
}
else
{
if
(
getColumnIndexByNameEx
(
&
pParamElem
->
pNode
->
colInfo
,
pCmd
,
&
index
)
!=
TSDB_CODE_SUCCESS
)
{
setErrMsg
(
pCmd
,
msg3
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg3
);
}
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
pCmd
,
index
.
tableIndex
);
...
...
@@ -2170,8 +2085,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, int32_t colIdx, tSQLExprItem* pItem
// functions can not be applied to tags
if
(
index
.
columnIndex
>=
pMeterMetaInfo
->
pMeterMeta
->
numOfColumns
)
{
setErrMsg
(
pCmd
,
msg6
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg6
);
}
if
(
setExprInfoForFunctions
(
pCmd
,
pSchema
,
functionID
,
pItem
->
aliasName
,
colIdx
+
i
,
&
index
)
!=
0
)
{
...
...
@@ -2208,14 +2122,12 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, int32_t colIdx, tSQLExprItem* pItem
// 1. valid the number of parameters
if
(
pItem
->
pNode
->
pParam
==
NULL
||
pItem
->
pNode
->
pParam
->
nExpr
!=
2
)
{
/* no parameters or more than one parameter for function */
setErrMsg
(
pCmd
,
msg2
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg2
);
}
tSQLExprItem
*
pParamElem
=
&
(
pItem
->
pNode
->
pParam
->
a
[
0
]);
if
(
pParamElem
->
pNode
->
nSQLOptr
!=
TK_ID
)
{
setErrMsg
(
pCmd
,
msg2
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg2
);
}
char
columnName
[
TSDB_COL_NAME_LEN
]
=
{
0
};
...
...
@@ -2223,8 +2135,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, int32_t colIdx, tSQLExprItem* pItem
SColumnIndex
index
=
COLUMN_INDEX_INITIALIZER
;
if
(
getColumnIndexByNameEx
(
&
pParamElem
->
pNode
->
colInfo
,
pCmd
,
&
index
)
!=
TSDB_CODE_SUCCESS
)
{
setErrMsg
(
pCmd
,
msg3
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg3
);
}
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
pCmd
,
index
.
tableIndex
);
...
...
@@ -2232,21 +2143,18 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, int32_t colIdx, tSQLExprItem* pItem
// functions can not be applied to tags
if
(
index
.
columnIndex
>=
pMeterMetaInfo
->
pMeterMeta
->
numOfColumns
)
{
setErrMsg
(
pCmd
,
msg6
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg6
);
}
// 2. valid the column type
int16_t
colType
=
pSchema
[
index
.
columnIndex
].
type
;
if
(
colType
==
TSDB_DATA_TYPE_BOOL
||
colType
>=
TSDB_DATA_TYPE_BINARY
)
{
setErrMsg
(
pCmd
,
msg1
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg1
);
}
// 3. valid the parameters
if
(
pParamElem
[
1
].
pNode
->
nSQLOptr
==
TK_ID
)
{
setErrMsg
(
pCmd
,
msg2
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg2
);
}
tVariant
*
pVariant
=
&
pParamElem
[
1
].
pNode
->
val
;
...
...
@@ -2260,8 +2168,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, int32_t colIdx, tSQLExprItem* pItem
double
dp
=
*
((
double
*
)
val
);
if
(
dp
<
0
||
dp
>
TOP_BOTTOM_QUERY_LIMIT
)
{
setErrMsg
(
pCmd
,
msg5
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg5
);
}
resultSize
=
sizeof
(
double
);
...
...
@@ -2284,8 +2191,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, int32_t colIdx, tSQLExprItem* pItem
int64_t
nTop
=
*
((
int32_t
*
)
val
);
if
(
nTop
<=
0
||
nTop
>
100
)
{
// todo use macro
setErrMsg
(
pCmd
,
msg5
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg5
);
}
int16_t
functionId
=
0
;
...
...
@@ -2392,8 +2298,7 @@ int32_t doGetColumnIndexByName(SSQLToken* pToken, SSqlCmd* pCmd, SColumnIndex* p
if
(
colIndex
!=
COLUMN_INDEX_INITIAL_VAL
)
{
if
(
pIndex
->
columnIndex
!=
COLUMN_INDEX_INITIAL_VAL
)
{
setErrMsg
(
pCmd
,
msg0
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg0
);
}
else
{
pIndex
->
tableIndex
=
i
;
pIndex
->
columnIndex
=
colIndex
;
...
...
@@ -2408,8 +2313,7 @@ int32_t doGetColumnIndexByName(SSQLToken* pToken, SSqlCmd* pCmd, SColumnIndex* p
}
if
(
pIndex
->
columnIndex
==
COLUMN_INDEX_INITIAL_VAL
)
{
setErrMsg
(
pCmd
,
msg1
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg1
);
}
}
...
...
@@ -2613,13 +2517,11 @@ int32_t setShowInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
SSQLToken
*
pDbPrefixToken
=
&
pInfo
->
pDCLInfo
->
a
[
0
];
if
(
pDbPrefixToken
->
n
>
TSDB_DB_NAME_LEN
)
{
// db name is too long
setErrMsg
(
pCmd
,
msg
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg
);
}
if
(
pDbPrefixToken
->
n
>
0
&&
tscValidateName
(
pDbPrefixToken
)
!=
TSDB_CODE_SUCCESS
)
{
setErrMsg
(
pCmd
,
msg1
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg1
);
}
int32_t
ret
=
0
;
...
...
@@ -2639,8 +2541,7 @@ int32_t setShowInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
pCmd
->
payloadLen
=
strdequote
(
pCmd
->
payload
);
if
(
pCmd
->
payloadLen
>
TSDB_METER_NAME_LEN
)
{
setErrMsg
(
pCmd
,
msg2
);
return
TSDB_CODE_INVALID_SQL
;
// wildcard is too long
return
invalidSqlErrMsg
(
pCmd
,
msg2
);
}
}
}
...
...
@@ -2650,8 +2551,7 @@ int32_t setShowInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
SSQLToken
*
pDnodeIp
=
&
pInfo
->
pDCLInfo
->
a
[
0
];
if
(
pDnodeIp
->
n
>
TSDB_IPv4ADDR_LEN
)
{
// ip addr is too long
setErrMsg
(
pCmd
,
msg
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg
);
}
strncpy
(
pCmd
->
payload
,
pDnodeIp
->
z
,
pDnodeIp
->
n
);
...
...
@@ -2694,8 +2594,7 @@ int32_t setKillInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
memset
(
pCmd
->
payload
,
0
,
tListLen
(
pCmd
->
payload
));
const
char
*
msg
=
"invalid ip address"
;
setErrMsg
(
pCmd
,
msg
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg
);
}
uint16_t
port
=
(
uint16_t
)
strtol
(
portStr
,
NULL
,
10
);
...
...
@@ -2703,18 +2602,12 @@ int32_t setKillInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
memset
(
pCmd
->
payload
,
0
,
tListLen
(
pCmd
->
payload
));
const
char
*
msg
=
"invalid port"
;
setErrMsg
(
pCmd
,
msg
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg
);
}
return
TSDB_CODE_SUCCESS
;
}
void
setErrMsg
(
SSqlCmd
*
pCmd
,
const
char
*
pzErrMsg
)
{
strncpy
(
pCmd
->
payload
,
pzErrMsg
,
pCmd
->
allocSize
);
pCmd
->
payload
[
pCmd
->
allocSize
-
1
]
=
0
;
}
bool
validateIpAddress
(
char
*
ip
)
{
in_addr_t
ipAddr
=
inet_addr
(
ip
);
return
(
ipAddr
!=
0
)
&&
(
ipAddr
!=
0xffffffff
);
...
...
@@ -2790,12 +2683,12 @@ bool hasUnsupportFunctionsForMetricQuery(SSqlCmd* pCmd) {
if
(
tscIsTWAQuery
(
pCmd
))
{
if
(
pCmd
->
groupbyExpr
.
numOfGroupCols
==
0
)
{
set
ErrMsg
(
pCmd
,
msg1
);
invalidSql
ErrMsg
(
pCmd
,
msg1
);
return
true
;
}
if
(
pCmd
->
groupbyExpr
.
numOfGroupCols
!=
1
||
pCmd
->
groupbyExpr
.
columnInfo
[
0
].
colIdx
!=
TSDB_TBNAME_COLUMN_INDEX
)
{
set
ErrMsg
(
pCmd
,
msg3
);
invalidSql
ErrMsg
(
pCmd
,
msg3
);
return
true
;
}
}
...
...
@@ -2889,8 +2782,7 @@ int32_t parseGroupbyClause(SSqlCmd* pCmd, tVariantList* pList) {
pCmd
->
groupbyExpr
.
numOfGroupCols
=
pList
->
nExpr
;
if
(
pList
->
nExpr
>
TSDB_MAX_TAGS
)
{
setErrMsg
(
pCmd
,
msg1
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg1
);
}
SMeterMeta
*
pMeterMeta
=
NULL
;
...
...
@@ -2907,13 +2799,11 @@ int32_t parseGroupbyClause(SSqlCmd* pCmd, tVariantList* pList) {
SColumnIndex
index
=
COLUMN_INDEX_INITIALIZER
;
if
(
getColumnIndexByNameEx
(
&
token
,
pCmd
,
&
index
)
!=
TSDB_CODE_SUCCESS
)
{
setErrMsg
(
pCmd
,
msg2
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg2
);
}
if
(
tableIndex
!=
index
.
tableIndex
&&
tableIndex
>=
0
)
{
setErrMsg
(
pCmd
,
msg5
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg5
);
}
tableIndex
=
index
.
tableIndex
;
...
...
@@ -2944,8 +2834,7 @@ int32_t parseGroupbyClause(SSqlCmd* pCmd, tVariantList* pList) {
if
(
groupTag
)
{
if
(
!
UTIL_METER_IS_METRIC
(
pMeterMetaInfo
))
{
setErrMsg
(
pCmd
,
msg9
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg9
);
}
int32_t
relIndex
=
index
.
columnIndex
;
...
...
@@ -2959,8 +2848,7 @@ int32_t parseGroupbyClause(SSqlCmd* pCmd, tVariantList* pList) {
}
else
{
// check if the column type is valid, here only support the bool/tinyint/smallint/bigint group by
if
(
pSchema
->
type
>
TSDB_DATA_TYPE_BIGINT
)
{
setErrMsg
(
pCmd
,
msg8
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg8
);
}
tscColumnBaseInfoInsert
(
pCmd
,
&
index
);
...
...
@@ -2969,8 +2857,7 @@ int32_t parseGroupbyClause(SSqlCmd* pCmd, tVariantList* pList) {
pCmd
->
groupbyExpr
.
orderType
=
TSQL_SO_ASC
;
if
(
i
==
0
&&
pList
->
nExpr
>
1
)
{
setErrMsg
(
pCmd
,
msg7
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg7
);
}
}
}
...
...
@@ -3072,8 +2959,7 @@ static int32_t doExtractColumnFilterInfo(SSqlCmd* pCmd, SColumnFilterInfo* pColu
pColumnFilter
->
lowerRelOptr
=
TSDB_RELATION_LIKE
;
break
;
default:
setErrMsg
(
pCmd
,
msg
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg
);
}
return
TSDB_CODE_SUCCESS
;
...
...
@@ -3295,13 +3181,11 @@ static int32_t extractColumnFilterInfo(SSqlCmd* pCmd, SColumnIndex* pIndex, tSQL
if
(
pColFilter
->
filterOnBinary
)
{
if
(
pExpr
->
nSQLOptr
!=
TK_EQ
&&
pExpr
->
nSQLOptr
!=
TK_NE
&&
pExpr
->
nSQLOptr
!=
TK_LIKE
)
{
setErrMsg
(
pCmd
,
msg2
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg2
);
}
}
else
{
if
(
pExpr
->
nSQLOptr
==
TK_LIKE
)
{
setErrMsg
(
pCmd
,
msg1
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg1
);
}
}
...
...
@@ -3376,7 +3260,7 @@ static int32_t getTablenameCond(SSqlCmd* pCmd, tSQLExpr* pTableCond, char* str)
}
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
set
ErrMsg
(
pCmd
,
msg0
);
invalidSql
ErrMsg
(
pCmd
,
msg0
);
}
return
ret
;
...
...
@@ -3414,8 +3298,7 @@ static int32_t getJoinCondInfo(SSqlObj* pSql, tSQLExpr* pExpr) {
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
if
(
!
isExprDirectParentOfLeaftNode
(
pExpr
))
{
setErrMsg
(
pCmd
,
msg
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg
);
}
STagCond
*
pTagCond
=
&
pCmd
->
tagCond
;
...
...
@@ -3626,14 +3509,14 @@ static bool validateJoinExprNode(SSqlCmd* pCmd, tSQLExpr* pExpr, SColumnIndex* p
}
if
(
pExpr
->
nSQLOptr
!=
TK_EQ
)
{
set
ErrMsg
(
pCmd
,
msg2
);
invalidSql
ErrMsg
(
pCmd
,
msg2
);
return
false
;
}
SColumnIndex
rightIndex
=
COLUMN_INDEX_INITIALIZER
;
if
(
getColumnIndexByNameEx
(
&
pRight
->
colInfo
,
pCmd
,
&
rightIndex
)
!=
TSDB_CODE_SUCCESS
)
{
set
ErrMsg
(
pCmd
,
msg1
);
invalidSql
ErrMsg
(
pCmd
,
msg1
);
return
false
;
}
...
...
@@ -3647,19 +3530,19 @@ static bool validateJoinExprNode(SSqlCmd* pCmd, tSQLExpr* pExpr, SColumnIndex* p
int16_t
rightType
=
pRightSchema
[
rightIndex
.
columnIndex
].
type
;
if
(
leftType
!=
rightType
)
{
set
ErrMsg
(
pCmd
,
msg3
);
invalidSql
ErrMsg
(
pCmd
,
msg3
);
return
false
;
}
else
if
(
pLeftIndex
->
tableIndex
==
rightIndex
.
tableIndex
)
{
set
ErrMsg
(
pCmd
,
msg4
);
invalidSql
ErrMsg
(
pCmd
,
msg4
);
return
false
;
}
else
if
(
leftType
==
TSDB_DATA_TYPE_BINARY
||
leftType
==
TSDB_DATA_TYPE_NCHAR
)
{
set
ErrMsg
(
pCmd
,
msg6
);
invalidSql
ErrMsg
(
pCmd
,
msg6
);
return
false
;
}
// table to table/ super table to super table are allowed
if
(
UTIL_METER_IS_METRIC
(
pLeftMeterMeta
)
!=
UTIL_METER_IS_METRIC
(
pRightMeterMeta
))
{
set
ErrMsg
(
pCmd
,
msg5
);
invalidSql
ErrMsg
(
pCmd
,
msg5
);
return
false
;
}
...
...
@@ -3681,8 +3564,7 @@ static bool validTableNameOptr(tSQLExpr* pExpr) {
static
int32_t
setExprToCond
(
SSqlCmd
*
pCmd
,
tSQLExpr
**
parent
,
tSQLExpr
*
pExpr
,
const
char
*
msg
,
int32_t
parentOptr
)
{
if
(
*
parent
!=
NULL
)
{
if
(
parentOptr
==
TK_OR
&&
msg
!=
NULL
)
{
setErrMsg
(
pCmd
,
msg
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg
);
}
*
parent
=
tSQLExprCreate
((
*
parent
),
pExpr
,
parentOptr
);
...
...
@@ -3711,8 +3593,7 @@ static int32_t handleExprInQueryCond(SSqlCmd* pCmd, tSQLExpr** pExpr, SCondExpr*
SColumnIndex
index
=
COLUMN_INDEX_INITIALIZER
;
if
(
getColumnIndexByNameEx
(
&
pLeft
->
colInfo
,
pCmd
,
&
index
)
!=
TSDB_CODE_SUCCESS
)
{
setErrMsg
(
pCmd
,
msg2
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg2
);
}
assert
(
isExprDirectParentOfLeaftNode
(
*
pExpr
));
...
...
@@ -3745,8 +3626,7 @@ static int32_t handleExprInQueryCond(SSqlCmd* pCmd, tSQLExpr** pExpr, SCondExpr*
index
.
columnIndex
==
TSDB_TBNAME_COLUMN_INDEX
)
{
// query on tags
// check for tag query condition
if
(
UTIL_METER_IS_NOMRAL_METER
(
pMeterMetaInfo
))
{
setErrMsg
(
pCmd
,
msg1
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg1
);
}
// check for like expression
...
...
@@ -3759,16 +3639,14 @@ static int32_t handleExprInQueryCond(SSqlCmd* pCmd, tSQLExpr** pExpr, SCondExpr*
if
((
!
isTablenameToken
(
&
pLeft
->
colInfo
))
&&
pSchema
[
index
.
columnIndex
].
type
!=
TSDB_DATA_TYPE_BINARY
&&
pSchema
[
index
.
columnIndex
].
type
!=
TSDB_DATA_TYPE_NCHAR
)
{
setErrMsg
(
pCmd
,
msg2
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg2
);
}
}
// in case of in operator, keep it in a seperate attribute
if
(
index
.
columnIndex
==
TSDB_TBNAME_COLUMN_INDEX
)
{
if
(
!
validTableNameOptr
(
*
pExpr
))
{
setErrMsg
(
pCmd
,
msg8
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg8
);
}
if
(
pCondExpr
->
pTableCond
==
NULL
)
{
...
...
@@ -3776,8 +3654,7 @@ static int32_t handleExprInQueryCond(SSqlCmd* pCmd, tSQLExpr** pExpr, SCondExpr*
pCondExpr
->
relType
=
parentOptr
;
pCondExpr
->
tableCondIndex
=
index
.
tableIndex
;
}
else
{
setErrMsg
(
pCmd
,
msg7
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg7
);
}
*
type
=
TSQL_EXPR_TBNAME
;
...
...
@@ -3789,8 +3666,7 @@ static int32_t handleExprInQueryCond(SSqlCmd* pCmd, tSQLExpr** pExpr, SCondExpr*
}
if
(
pCondExpr
->
pJoinExpr
!=
NULL
)
{
setErrMsg
(
pCmd
,
msg4
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg4
);
}
pCmd
->
type
|=
TSDB_QUERY_TYPE_JOIN_QUERY
;
...
...
@@ -3809,15 +3685,9 @@ static int32_t handleExprInQueryCond(SSqlCmd* pCmd, tSQLExpr** pExpr, SCondExpr*
*
type
=
TSQL_EXPR_COLUMN
;
if
(
pRight
->
nSQLOptr
==
TK_ID
)
{
// other column cannot be served as the join column
setErrMsg
(
pCmd
,
msg6
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg6
);
}
// if (parentOptr == TK_OR) {
// setErrMsg(pCmd, msg5);
// return TSDB_CODE_INVALID_SQL;
// }
ret
=
setExprToCond
(
pCmd
,
&
pCondExpr
->
pColumnCond
,
*
pExpr
,
NULL
,
parentOptr
);
*
pExpr
=
NULL
;
// remove it from expr tree
}
...
...
@@ -3859,8 +3729,7 @@ int32_t getQueryCondExpr(SSqlCmd* pCmd, tSQLExpr** pExpr, SCondExpr* pCondExpr,
*/
if
(
leftType
!=
rightType
)
{
if
((
*
pExpr
)
->
nSQLOptr
==
TK_OR
&&
(
leftType
+
rightType
!=
TSQL_EXPR_TBNAME
+
TSQL_EXPR_TAG
))
{
setErrMsg
(
pCmd
,
msg1
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg1
);
}
}
...
...
@@ -4014,7 +3883,7 @@ static int32_t setTableCondForMetricQuery(SSqlObj* pSql, tSQLExpr* pExpr, int16_
int32_t
ret
=
setObjFullName
(
pTableCond
->
z
+
pTableCond
->
n
,
acc
,
&
dbToken
,
&
t
,
&
xlen
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
tfree
(
segments
);
set
ErrMsg
(
pCmd
,
msg
);
invalidSql
ErrMsg
(
pCmd
,
msg
);
return
ret
;
}
...
...
@@ -4059,8 +3928,7 @@ static int32_t getTimeRangeFromExpr(SSqlCmd* pCmd, tSQLExpr* pExpr) {
if
(
!
isExprDirectParentOfLeaftNode
(
pExpr
))
{
if
(
pExpr
->
nSQLOptr
==
TK_OR
)
{
setErrMsg
(
pCmd
,
msg1
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg1
);
}
getTimeRangeFromExpr
(
pCmd
,
pExpr
->
pLeft
);
...
...
@@ -4081,8 +3949,7 @@ static int32_t getTimeRangeFromExpr(SSqlCmd* pCmd, tSQLExpr* pExpr) {
TSKEY
etime
=
INT64_MAX
;
if
(
getTimeRange
(
&
stime
,
&
etime
,
pRight
,
pExpr
->
nSQLOptr
,
pMeterMeta
->
precision
)
!=
TSDB_CODE_SUCCESS
)
{
setErrMsg
(
pCmd
,
msg0
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg0
);
}
// update the timestamp query range
...
...
@@ -4107,8 +3974,7 @@ static int32_t validateJoinExpr(SSqlCmd* pCmd, SCondExpr* pCondExpr) {
if
(
pCmd
->
numOfTables
==
1
)
{
return
TSDB_CODE_SUCCESS
;
}
else
{
setErrMsg
(
pCmd
,
msg3
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg3
);
}
}
...
...
@@ -4116,14 +3982,12 @@ static int32_t validateJoinExpr(SSqlCmd* pCmd, SCondExpr* pCondExpr) {
if
(
UTIL_METER_IS_METRIC
(
pMeterMetaInfo
))
{
// for stable join, tag columns
// must be present for join
if
(
pCondExpr
->
pJoinExpr
==
NULL
)
{
setErrMsg
(
pCmd
,
msg1
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg1
);
}
}
if
(
!
pCondExpr
->
tsJoin
)
{
setErrMsg
(
pCmd
,
msg2
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg2
);
}
return
TSDB_CODE_SUCCESS
;
...
...
@@ -4167,8 +4031,7 @@ int32_t parseWhereClause(SSqlObj* pSql, tSQLExpr** pExpr) {
SCondExpr
condExpr
=
{
0
};
if
((
*
pExpr
)
->
pLeft
==
NULL
||
(
*
pExpr
)
->
pRight
==
NULL
)
{
setErrMsg
(
pCmd
,
msg1
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg1
);
}
ret
=
doParseWhereClause
(
pSql
,
pExpr
,
&
condExpr
);
...
...
@@ -4270,8 +4133,7 @@ int32_t doParseWhereClause(SSqlObj* pSql, tSQLExpr** pExpr, SCondExpr* condExpr)
pCmd
->
tagCond
.
relType
=
(
condExpr
->
relType
==
TK_AND
)
?
TSDB_RELATION_AND
:
TSDB_RELATION_OR
;
ret
=
setTableCondForMetricQuery
(
pSql
,
condExpr
->
pTableCond
,
condExpr
->
tableCondIndex
,
tableNameCond
);
if
(
!
validateFilterExpr
(
pCmd
))
{
setErrMsg
(
pCmd
,
msg
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg
);
}
return
ret
;
...
...
@@ -4389,8 +4251,7 @@ int32_t tsRewriteFieldNameIfNecessary(SSqlCmd* pCmd) {
for
(
int32_t
j
=
i
+
1
;
j
<
pCmd
->
fieldsInfo
.
numOfOutputCols
;
++
j
)
{
if
(
strncasecmp
(
fieldName
,
tscFieldInfoGetField
(
pCmd
,
j
)
->
name
,
TSDB_COL_NAME_LEN
)
==
0
)
{
const
char
*
msg
=
"duplicated column name in new table"
;
setErrMsg
(
pCmd
,
msg
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg
);
}
}
}
...
...
@@ -4408,8 +4269,7 @@ int32_t parseFillClause(SSqlCmd* pCmd, SQuerySQL* pQuerySQL) {
const
char
*
msg2
=
"invalid fill option"
;
if
(
pItem
->
pVar
.
nType
!=
TSDB_DATA_TYPE_BINARY
)
{
setErrMsg
(
pCmd
,
msg2
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg2
);
}
if
(
strncasecmp
(
pItem
->
pVar
.
pz
,
"none"
,
4
)
==
0
&&
pItem
->
pVar
.
nLen
==
4
)
{
...
...
@@ -4429,8 +4289,7 @@ int32_t parseFillClause(SSqlCmd* pCmd, SQuerySQL* pQuerySQL) {
pCmd
->
interpoType
=
TSDB_INTERPO_SET_VALUE
;
if
(
pFillToken
->
nExpr
==
1
)
{
setErrMsg
(
pCmd
,
msg1
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg1
);
}
int32_t
startPos
=
1
;
...
...
@@ -4455,8 +4314,7 @@ int32_t parseFillClause(SSqlCmd* pCmd, SQuerySQL* pQuerySQL) {
int32_t
ret
=
tVariantDump
(
&
pFillToken
->
a
[
j
].
pVar
,
(
char
*
)
&
pCmd
->
defaultVal
[
i
],
pFields
->
type
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
setErrMsg
(
pCmd
,
msg
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg
);
}
if
(
pFields
->
type
==
TSDB_DATA_TYPE_BINARY
||
pFields
->
type
==
TSDB_DATA_TYPE_NCHAR
)
{
...
...
@@ -4478,8 +4336,7 @@ int32_t parseFillClause(SSqlCmd* pCmd, SQuerySQL* pQuerySQL) {
}
}
}
else
{
setErrMsg
(
pCmd
,
msg2
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg2
);
}
return
TSDB_CODE_SUCCESS
;
...
...
@@ -4526,13 +4383,11 @@ int32_t parseOrderbyClause(SSqlCmd* pCmd, SQuerySQL* pQuerySql, SSchema* pSchema
*/
if
(
UTIL_METER_IS_NOMRAL_METER
(
pMeterMetaInfo
))
{
if
(
pSortorder
->
nExpr
>
1
)
{
setErrMsg
(
pCmd
,
msg0
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg0
);
}
}
else
{
if
(
pSortorder
->
nExpr
>
2
)
{
setErrMsg
(
pCmd
,
msg3
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg3
);
}
}
...
...
@@ -4549,8 +4404,7 @@ int32_t parseOrderbyClause(SSqlCmd* pCmd, SQuerySQL* pQuerySql, SSchema* pSchema
if
(
UTIL_METER_IS_METRIC
(
pMeterMetaInfo
))
{
// metric query
if
(
getColumnIndexByNameEx
(
&
columnName
,
pCmd
,
&
index
)
!=
TSDB_CODE_SUCCESS
)
{
setErrMsg
(
pCmd
,
msg1
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg1
);
}
bool
orderByTags
=
false
;
...
...
@@ -4571,8 +4425,7 @@ int32_t parseOrderbyClause(SSqlCmd* pCmd, SQuerySQL* pQuerySql, SSchema* pSchema
}
if
(
!
(
orderByTags
||
orderByTS
)
&&
!
isTopBottomQuery
(
pCmd
))
{
setErrMsg
(
pCmd
,
msg3
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg3
);
}
else
{
assert
(
!
(
orderByTags
&&
orderByTS
));
}
...
...
@@ -4588,8 +4441,7 @@ int32_t parseOrderbyClause(SSqlCmd* pCmd, SQuerySQL* pQuerySql, SSchema* pSchema
pExpr
=
tscSqlExprGet
(
pCmd
,
1
);
if
(
pExpr
->
colInfo
.
colIdx
!=
index
.
columnIndex
&&
index
.
columnIndex
!=
PRIMARYKEY_TIMESTAMP_COL_INDEX
)
{
setErrMsg
(
pCmd
,
msg2
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg2
);
}
pCmd
->
order
.
order
=
pQuerySql
->
pSortOrder
->
a
[
0
].
sortOrder
;
...
...
@@ -4613,13 +4465,11 @@ int32_t parseOrderbyClause(SSqlCmd* pCmd, SQuerySQL* pQuerySql, SSchema* pSchema
tVariant
*
pVar2
=
&
pSortorder
->
a
[
1
].
pVar
;
SSQLToken
cname
=
{
pVar2
->
nLen
,
pVar2
->
nType
,
pVar2
->
pz
};
if
(
getColumnIndexByNameEx
(
&
cname
,
pCmd
,
&
index
)
!=
TSDB_CODE_SUCCESS
)
{
setErrMsg
(
pCmd
,
msg1
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg1
);
}
if
(
index
.
columnIndex
!=
PRIMARYKEY_TIMESTAMP_COL_INDEX
)
{
setErrMsg
(
pCmd
,
msg2
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg2
);
}
else
{
pCmd
->
order
.
order
=
pSortorder
->
a
[
1
].
sortOrder
;
pCmd
->
order
.
orderColId
=
PRIMARYKEY_TIMESTAMP_COL_INDEX
;
...
...
@@ -4628,13 +4478,11 @@ int32_t parseOrderbyClause(SSqlCmd* pCmd, SQuerySQL* pQuerySql, SSchema* pSchema
}
else
{
// meter query
if
(
getColumnIndexByNameEx
(
&
columnName
,
pCmd
,
&
index
)
!=
TSDB_CODE_SUCCESS
)
{
setErrMsg
(
pCmd
,
msg1
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg1
);
}
if
(
index
.
columnIndex
!=
PRIMARYKEY_TIMESTAMP_COL_INDEX
&&
!
isTopBottomQuery
(
pCmd
))
{
setErrMsg
(
pCmd
,
msg2
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg2
);
}
if
(
isTopBottomQuery
(
pCmd
))
{
...
...
@@ -4644,8 +4492,7 @@ int32_t parseOrderbyClause(SSqlCmd* pCmd, SQuerySQL* pQuerySql, SSchema* pSchema
pExpr
=
tscSqlExprGet
(
pCmd
,
1
);
if
(
pExpr
->
colInfo
.
colIdx
!=
index
.
columnIndex
&&
index
.
columnIndex
!=
PRIMARYKEY_TIMESTAMP_COL_INDEX
)
{
setErrMsg
(
pCmd
,
msg2
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg2
);
}
pCmd
->
order
.
order
=
pQuerySql
->
pSortOrder
->
a
[
0
].
sortOrder
;
...
...
@@ -4670,14 +4517,12 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
if
(
tscValidateName
(
&
(
pAlterSQL
->
name
))
!=
TSDB_CODE_SUCCESS
)
{
const
char
*
msg
=
"invalid table name"
;
setErrMsg
(
pCmd
,
msg
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg
);
}
if
(
setMeterID
(
pSql
,
&
(
pAlterSQL
->
name
),
0
)
!=
TSDB_CODE_SUCCESS
)
{
const
char
*
msg
=
"table name too long"
;
setErrMsg
(
pCmd
,
msg
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg
);
}
int32_t
ret
=
tscGetMeterMeta
(
pSql
,
pMeterMetaInfo
->
name
,
DEFAULT_TABLE_INDEX
);
...
...
@@ -4692,18 +4537,15 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
pInfo
->
sqlType
==
ALTER_TABLE_TAGS_CHG
)
{
if
(
UTIL_METER_IS_NOMRAL_METER
(
pMeterMetaInfo
))
{
const
char
*
msg
=
"manipulation of tag available for metric"
;
setErrMsg
(
pCmd
,
msg
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg
);
}
}
else
if
((
pInfo
->
sqlType
==
ALTER_TABLE_TAGS_SET
)
&&
(
UTIL_METER_IS_METRIC
(
pMeterMetaInfo
)))
{
const
char
*
msg
=
"set tag value only available for table"
;
setErrMsg
(
pCmd
,
msg
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg
);
}
else
if
((
pInfo
->
sqlType
==
ALTER_TABLE_ADD_COLUMN
||
pInfo
->
sqlType
==
ALTER_TABLE_DROP_COLUMN
)
&&
UTIL_METER_IS_CREATE_FROM_METRIC
(
pMeterMetaInfo
))
{
const
char
*
msg
=
"column can only be modified by metric"
;
setErrMsg
(
pCmd
,
msg
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg
);
}
if
(
pInfo
->
sqlType
==
ALTER_TABLE_TAGS_ADD
)
{
...
...
@@ -4712,8 +4554,7 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
tFieldList
*
pFieldList
=
pAlterSQL
->
pAddColumns
;
if
(
pFieldList
->
nField
>
1
)
{
const
char
*
msg
=
"only support add one tag"
;
setErrMsg
(
pCmd
,
msg
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg
);
}
if
(
!
validateOneTags
(
pCmd
,
&
pFieldList
->
p
[
0
]))
{
...
...
@@ -4733,20 +4574,17 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
const
char
*
msg5
=
"primary tag cannot be dropped"
;
if
(
pMeterMeta
->
numOfTags
==
1
)
{
setErrMsg
(
pCmd
,
msg1
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg1
);
}
// numOfTags == 1
if
(
pAlterSQL
->
varList
->
nExpr
>
1
)
{
setErrMsg
(
pCmd
,
msg2
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg2
);
}
tVariantListItem
*
pItem
=
&
pAlterSQL
->
varList
->
a
[
0
];
if
(
pItem
->
pVar
.
nLen
>
TSDB_COL_NAME_LEN
)
{
setErrMsg
(
pCmd
,
msg3
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg3
);
}
int32_t
idx
=
-
1
;
...
...
@@ -4762,11 +4600,9 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
}
if
(
idx
==
-
1
)
{
setErrMsg
(
pCmd
,
msg4
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg4
);
}
else
if
(
idx
==
0
)
{
setErrMsg
(
pCmd
,
msg5
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg5
);
}
char
name
[
128
]
=
{
0
};
...
...
@@ -4789,13 +4625,11 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
tVariantListItem
*
pDstItem
=
&
pAlterSQL
->
varList
->
a
[
1
];
if
(
pSrcItem
->
pVar
.
nLen
>=
TSDB_COL_NAME_LEN
||
pDstItem
->
pVar
.
nLen
>=
TSDB_COL_NAME_LEN
)
{
setErrMsg
(
pCmd
,
msg1
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg1
);
}
if
(
pSrcItem
->
pVar
.
nType
!=
TSDB_DATA_TYPE_BINARY
||
pDstItem
->
pVar
.
nType
!=
TSDB_DATA_TYPE_BINARY
)
{
setErrMsg
(
pCmd
,
msg2
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg2
);
}
SColumnIndex
srcIndex
=
COLUMN_INDEX_INITIALIZER
;
...
...
@@ -4835,8 +4669,7 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
tVariant
*
pTagName
=
&
pVarList
->
a
[
0
].
pVar
;
if
(
pTagName
->
nLen
>
TSDB_COL_NAME_LEN
)
{
setErrMsg
(
pCmd
,
msg0
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg0
);
}
int32_t
tagsIndex
=
-
1
;
...
...
@@ -4850,20 +4683,17 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
}
if
(
tagsIndex
==
-
1
)
{
setErrMsg
(
pCmd
,
msg2
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg2
);
}
if
(
tVariantDump
(
&
pVarList
->
a
[
1
].
pVar
,
pCmd
->
payload
,
pTagsSchema
[
tagsIndex
].
type
)
!=
TSDB_CODE_SUCCESS
)
{
setErrMsg
(
pCmd
,
msg1
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg1
);
}
// validate the length of binary
if
((
pTagsSchema
[
tagsIndex
].
type
==
TSDB_DATA_TYPE_BINARY
||
pTagsSchema
[
tagsIndex
].
type
==
TSDB_DATA_TYPE_NCHAR
)
&&
pVarList
->
a
[
1
].
pVar
.
nLen
>
pTagsSchema
[
tagsIndex
].
bytes
)
{
setErrMsg
(
pCmd
,
msg3
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg3
);
}
char
name
[
128
]
=
{
0
};
...
...
@@ -4877,8 +4707,7 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
tFieldList
*
pFieldList
=
pAlterSQL
->
pAddColumns
;
if
(
pFieldList
->
nField
>
1
)
{
const
char
*
msg
=
"only support add one column"
;
setErrMsg
(
pCmd
,
msg
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg
);
}
if
(
!
validateOneColumn
(
pCmd
,
&
pFieldList
->
p
[
0
]))
{
...
...
@@ -4897,19 +4726,16 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
const
char
*
msg5
=
"primary timestamp column cannot be dropped"
;
if
(
pMeterMeta
->
numOfColumns
==
TSDB_MIN_COLUMNS
)
{
//
setErrMsg
(
pCmd
,
msg1
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg1
);
}
if
(
pAlterSQL
->
varList
->
nExpr
>
1
)
{
setErrMsg
(
pCmd
,
msg2
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg2
);
}
tVariantListItem
*
pItem
=
&
pAlterSQL
->
varList
->
a
[
0
];
if
(
pItem
->
pVar
.
nLen
>
TSDB_COL_NAME_LEN
)
{
setErrMsg
(
pCmd
,
msg3
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg3
);
}
int32_t
idx
=
-
1
;
...
...
@@ -4924,11 +4750,9 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
}
if
(
idx
==
-
1
)
{
setErrMsg
(
pCmd
,
msg4
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg4
);
}
else
if
(
idx
==
0
)
{
setErrMsg
(
pCmd
,
msg5
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg5
);
}
char
name
[
128
]
=
{
0
};
...
...
@@ -4946,15 +4770,13 @@ int32_t validateSqlFunctionInStreamSql(SSqlCmd* pCmd) {
const
char
*
msg1
=
"functions not allowed in select clause"
;
if
(
pCmd
->
nAggTimeInterval
!=
0
&&
pCmd
->
nAggTimeInterval
<
10
)
{
setErrMsg
(
pCmd
,
msg0
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg0
);
}
for
(
int32_t
i
=
0
;
i
<
pCmd
->
fieldsInfo
.
numOfOutputCols
;
++
i
)
{
int32_t
functId
=
tscSqlExprGet
(
pCmd
,
i
)
->
functionId
;
if
(
!
IS_STREAM_QUERY_VALID
(
aAggs
[
functId
].
nStatus
))
{
setErrMsg
(
pCmd
,
msg1
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg1
);
}
}
...
...
@@ -4993,7 +4815,7 @@ int32_t validateFunctionsInIntervalOrGroupbyQuery(SSqlCmd* pCmd) {
}
if
(
isProjectionFunction
)
{
set
ErrMsg
(
pCmd
,
msg1
);
invalidSql
ErrMsg
(
pCmd
,
msg1
);
}
return
isProjectionFunction
==
true
?
TSDB_CODE_INVALID_SQL
:
TSDB_CODE_SUCCESS
;
...
...
@@ -5148,8 +4970,7 @@ int32_t parseLimitClause(SSqlObj* pSql, SQuerySQL* pQuerySql) {
pCmd
->
slimit
=
pQuerySql
->
slimit
;
if
(
pCmd
->
slimit
.
offset
<
0
||
pCmd
->
limit
.
offset
<
0
)
{
setErrMsg
(
pCmd
,
msg0
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg0
);
}
if
(
pCmd
->
limit
.
limit
==
0
)
{
...
...
@@ -5167,8 +4988,7 @@ int32_t parseLimitClause(SSqlObj* pSql, SQuerySQL* pQuerySql) {
pCmd
->
command
=
TSDB_SQL_RETRIEVE_TAGS
;
}
else
{
if
(
tscProjectionQueryOnMetric
(
pCmd
)
&&
(
pCmd
->
slimit
.
limit
>
0
||
pCmd
->
slimit
.
offset
>
0
))
{
setErrMsg
(
pCmd
,
msg3
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg3
);
}
}
...
...
@@ -5199,16 +5019,14 @@ int32_t parseLimitClause(SSqlObj* pSql, SQuerySQL* pQuerySql) {
pCmd
->
globalLimit
=
pCmd
->
limit
.
limit
;
}
else
{
if
(
pCmd
->
slimit
.
limit
!=
-
1
||
pCmd
->
slimit
.
offset
!=
0
)
{
setErrMsg
(
pCmd
,
msg1
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg1
);
}
// filter the query functions operating on "tbname" column that are not supported by normal columns.
for
(
int32_t
i
=
0
;
i
<
pCmd
->
fieldsInfo
.
numOfOutputCols
;
++
i
)
{
SSqlExpr
*
pExpr
=
tscSqlExprGet
(
pCmd
,
i
);
if
(
pExpr
->
colInfo
.
colIdx
==
TSDB_TBNAME_COLUMN_INDEX
)
{
setErrMsg
(
pCmd
,
msg2
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg2
);
}
}
}
...
...
@@ -5241,8 +5059,7 @@ static int32_t setKeepOption(SSqlCmd* pCmd, SCreateDbMsg* pMsg, SCreateDBInfo* p
break
;
}
default:
{
setErrMsg
(
pCmd
,
msg
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg
);
}
}
}
...
...
@@ -5267,8 +5084,7 @@ static int32_t setTimePrecisionOption(SSqlCmd* pCmd, SCreateDbMsg* pMsg, SCreate
strlen
(
TSDB_TIME_PRECISION_MICRO_STR
)
==
pToken
->
n
)
{
pMsg
->
precision
=
TSDB_TIME_PRECISION_MICRO
;
}
else
{
setErrMsg
(
pCmd
,
msg
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg
);
}
}
...
...
@@ -5531,8 +5347,7 @@ static int32_t checkUpdateTagPrjFunctions(SSqlCmd* pCmd) {
// When the tag projection function on tag column that is not in the group by clause, aggregation function and
// selectivity function exist in select clause is not allowed.
if
(
numOfAggregation
>
0
)
{
setErrMsg
(
pCmd
,
msg1
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg1
);
}
/*
...
...
@@ -5553,8 +5368,7 @@ static int32_t checkUpdateTagPrjFunctions(SSqlCmd* pCmd) {
}
if
(((
aAggs
[
functionId
].
nStatus
&
TSDB_FUNCSTATE_SELECTIVITY
)
!=
0
)
&&
(
functionId
!=
TSDB_FUNC_LAST_ROW
))
{
setErrMsg
(
pCmd
,
msg1
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg1
);
}
}
...
...
@@ -5564,8 +5378,7 @@ static int32_t checkUpdateTagPrjFunctions(SSqlCmd* pCmd) {
}
else
{
if
((
pCmd
->
type
&
TSDB_QUERY_TYPE_PROJECTION_QUERY
)
==
TSDB_QUERY_TYPE_PROJECTION_QUERY
)
{
if
(
numOfAggregation
>
0
&&
pCmd
->
groupbyExpr
.
numOfGroupCols
==
0
)
{
setErrMsg
(
pCmd
,
msg3
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg3
);
}
if
(
numOfAggregation
>
0
||
numOfSelectivity
>
0
)
{
...
...
@@ -5620,8 +5433,7 @@ static int32_t doAddGroupbyColumnsOnDemand(SSqlCmd* pCmd) {
}
else
{
// if this query is "group by" normal column, interval is not allowed
if
(
pCmd
->
nAggTimeInterval
>
0
)
{
setErrMsg
(
pCmd
,
msg2
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg2
);
}
bool
hasGroupColumn
=
false
;
...
...
@@ -5658,8 +5470,7 @@ int32_t doFunctionsCompatibleCheck(SSqlObj* pSql) {
// only retrieve tags, group by is not supportted
if
(
pCmd
->
command
==
TSDB_SQL_RETRIEVE_TAGS
)
{
if
(
pCmd
->
groupbyExpr
.
numOfGroupCols
>
0
||
pCmd
->
nAggTimeInterval
>
0
)
{
setErrMsg
(
pCmd
,
msg5
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg5
);
}
else
{
return
TSDB_CODE_SUCCESS
;
}
...
...
@@ -5703,13 +5514,11 @@ int32_t doFunctionsCompatibleCheck(SSqlObj* pSql) {
if
(
IS_MULTIOUTPUT
(
aAggs
[
functId
].
nStatus
)
&&
functId
!=
TSDB_FUNC_TOP
&&
functId
!=
TSDB_FUNC_BOTTOM
&&
functId
!=
TSDB_FUNC_TAGPRJ
&&
functId
!=
TSDB_FUNC_PRJ
)
{
setErrMsg
(
pCmd
,
msg1
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg1
);
}
if
(
functId
==
TSDB_FUNC_COUNT
&&
pExpr
->
colInfo
.
colIdx
==
TSDB_TBNAME_COLUMN_INDEX
)
{
setErrMsg
(
pCmd
,
msg1
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg1
);
}
}
...
...
@@ -5727,8 +5536,7 @@ int32_t doFunctionsCompatibleCheck(SSqlObj* pSql) {
// projection query on metric does not compatible with "group by" syntax
if
(
tscProjectionQueryOnMetric
(
pCmd
))
{
setErrMsg
(
pCmd
,
msg3
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg3
);
}
return
TSDB_CODE_SUCCESS
;
...
...
@@ -5744,16 +5552,15 @@ int32_t doLocalQueryProcess(SQuerySQL* pQuerySql, SSqlCmd* pCmd) {
tSQLExprList
*
pExprList
=
pQuerySql
->
pSelection
;
if
(
pExprList
->
nExpr
!=
1
)
{
setErrMsg
(
pCmd
,
msg1
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg1
);
}
tSQLExpr
*
pExpr
=
pExprList
->
a
[
0
].
pNode
;
if
(
pExpr
->
operand
.
z
==
NULL
)
{
setErrMsg
(
pCmd
,
msg2
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg2
);
}
// TODO redefine the function
SDNodeDynConfOption
functionsInfo
[
5
]
=
{{
"database()"
,
10
},
{
"server_version()"
,
16
},
{
"server_status()"
,
15
},
...
...
@@ -5793,8 +5600,7 @@ int32_t doLocalQueryProcess(SQuerySQL* pQuerySql, SSqlCmd* pCmd) {
pCmd
->
command
=
TSDB_SQL_CURRENT_USER
;
return
TSDB_CODE_SUCCESS
;
default:
{
setErrMsg
(
pCmd
,
msg3
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg3
);
}
}
}
...
...
@@ -5805,80 +5611,70 @@ int32_t tscCheckCreateDbParams(SSqlCmd* pCmd, SCreateDbMsg *pCreate) {
if
(
pCreate
->
commitLog
!=
-
1
&&
(
pCreate
->
commitLog
<
0
||
pCreate
->
commitLog
>
1
))
{
snprintf
(
msg
,
tListLen
(
msg
),
"invalid db option commitLog: %d, only 0 or 1 allowed"
,
pCreate
->
commitLog
);
setErrMsg
(
pCmd
,
msg
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg
);
}
if
(
pCreate
->
replications
!=
-
1
&&
(
pCreate
->
replications
<
TSDB_REPLICA_MIN_NUM
||
pCreate
->
replications
>
TSDB_REPLICA_MAX_NUM
))
{
snprintf
(
msg
,
tListLen
(
msg
),
"invalid db option replications: %d valid range: [%d, %d]"
,
pCreate
->
replications
,
TSDB_REPLICA_MIN_NUM
,
TSDB_REPLICA_MAX_NUM
);
setErrMsg
(
pCmd
,
msg
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg
);
}
int32_t
val
=
htonl
(
pCreate
->
daysPerFile
);
if
(
val
!=
-
1
&&
(
val
<
TSDB_FILE_MIN_PARTITION_RANGE
||
val
>
TSDB_FILE_MAX_PARTITION_RANGE
))
{
snprintf
(
msg
,
tListLen
(
msg
),
"invalid db option daysPerFile: %d valid range: [%d, %d]"
,
val
,
TSDB_FILE_MIN_PARTITION_RANGE
,
TSDB_FILE_MAX_PARTITION_RANGE
);
setErrMsg
(
pCmd
,
msg
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg
);
}
val
=
htonl
(
pCreate
->
rowsInFileBlock
);
if
(
val
!=
-
1
&&
(
val
<
TSDB_MIN_ROWS_IN_FILEBLOCK
||
val
>
TSDB_MAX_ROWS_IN_FILEBLOCK
))
{
snprintf
(
msg
,
tListLen
(
msg
),
"invalid db option rowsInFileBlock: %d valid range: [%d, %d]"
,
val
,
TSDB_MIN_ROWS_IN_FILEBLOCK
,
TSDB_MAX_ROWS_IN_FILEBLOCK
);
setErrMsg
(
pCmd
,
msg
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg
);
}
val
=
htonl
(
pCreate
->
cacheBlockSize
);
if
(
val
!=
-
1
&&
(
val
<
TSDB_MIN_CACHE_BLOCK_SIZE
||
val
>
TSDB_MAX_CACHE_BLOCK_SIZE
))
{
snprintf
(
msg
,
tListLen
(
msg
),
"invalid db option cacheBlockSize: %d valid range: [%d, %d]"
,
val
,
TSDB_MIN_CACHE_BLOCK_SIZE
,
TSDB_MAX_CACHE_BLOCK_SIZE
);
setErrMsg
(
pCmd
,
msg
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg
);
}
val
=
htonl
(
pCreate
->
maxSessions
);
if
(
val
!=
-
1
&&
(
val
<
TSDB_MIN_TABLES_PER_VNODE
||
val
>
TSDB_MAX_TABLES_PER_VNODE
))
{
snprintf
(
msg
,
tListLen
(
msg
),
"invalid db option maxSessions: %d valid range: [%d, %d]"
,
val
,
TSDB_MIN_TABLES_PER_VNODE
,
TSDB_MAX_TABLES_PER_VNODE
);
setErrMsg
(
pCmd
,
msg
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg
);
}
if
(
pCreate
->
precision
!=
-
1
&&
(
pCreate
->
precision
!=
TSDB_TIME_PRECISION_MILLI
&&
pCreate
->
precision
!=
TSDB_TIME_PRECISION_MICRO
))
{
snprintf
(
msg
,
tListLen
(
msg
),
"invalid db option timePrecision: %d valid value: [%d, %d]"
,
pCreate
->
precision
,
TSDB_TIME_PRECISION_MILLI
,
TSDB_TIME_PRECISION_MICRO
);
setErrMsg
(
pCmd
,
msg
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg
);
}
if
(
pCreate
->
cacheNumOfBlocks
.
fraction
!=
-
1
&&
(
pCreate
->
cacheNumOfBlocks
.
fraction
<
TSDB_MIN_AVG_BLOCKS
||
pCreate
->
cacheNumOfBlocks
.
fraction
>
TSDB_MAX_AVG_BLOCKS
))
{
snprintf
(
msg
,
tListLen
(
msg
),
"invalid db option ablocks: %f valid value: [%d, %d]"
,
pCreate
->
cacheNumOfBlocks
.
fraction
,
TSDB_MIN_AVG_BLOCKS
,
TSDB_MAX_AVG_BLOCKS
);
setErrMsg
(
pCmd
,
msg
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg
);
}
val
=
htonl
(
pCreate
->
commitTime
);
if
(
val
!=
-
1
&&
(
val
<
TSDB_MIN_COMMIT_TIME_INTERVAL
||
val
>
TSDB_MAX_COMMIT_TIME_INTERVAL
))
{
snprintf
(
msg
,
tListLen
(
msg
),
"invalid db option commitTime: %d valid range: [%d, %d]"
,
val
,
TSDB_MIN_COMMIT_TIME_INTERVAL
,
TSDB_MAX_COMMIT_TIME_INTERVAL
);
setErrMsg
(
pCmd
,
msg
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg
);
}
if
(
pCreate
->
compression
!=
-
1
&&
(
pCreate
->
compression
<
TSDB_MIN_COMPRESSION_LEVEL
||
pCreate
->
compression
>
TSDB_MAX_COMPRESSION_LEVEL
))
{
snprintf
(
msg
,
tListLen
(
msg
),
"invalid db option compression: %d valid range: [%d, %d]"
,
pCreate
->
compression
,
TSDB_MIN_COMPRESSION_LEVEL
,
TSDB_MAX_COMPRESSION_LEVEL
);
setErrMsg
(
pCmd
,
msg
);
return
TSDB_CODE_INVALID_SQL
;
return
invalidSqlErrMsg
(
pCmd
,
msg
);
}
return
TSDB_CODE_SUCCESS
;
...
...
src/client/src/tscSchemaUtil.c
浏览文件 @
574f9d4c
...
...
@@ -123,6 +123,7 @@ bool tsMeterMetaIdentical(SMeterMeta* p1, SMeterMeta* p2) {
return
memcmp
(
p1
,
p2
,
size
)
==
0
;
}
//todo refactor
static
FORCE_INLINE
char
*
skipSegments
(
char
*
input
,
char
delimiter
,
int32_t
num
)
{
for
(
int32_t
i
=
0
;
i
<
num
;
++
i
)
{
while
(
*
input
!=
0
&&
*
input
++
!=
delimiter
)
{
...
...
src/client/src/tscServer.c
浏览文件 @
574f9d4c
...
...
@@ -1415,7 +1415,7 @@ int tscBuildSubmitMsg(SSqlObj *pSql) {
pMsg
=
pStart
;
pShellMsg
=
(
SShellSubmitMsg
*
)
pMsg
;
pShellMsg
->
import
=
pSql
->
cmd
.
order
.
order
;
pShellMsg
->
import
=
pSql
->
cmd
.
import
;
pShellMsg
->
vnode
=
htons
(
pMeterMeta
->
vpeerDesc
[
pMeterMeta
->
index
].
vnode
);
pShellMsg
->
numOfSid
=
htonl
(
pSql
->
cmd
.
count
);
// number of meters to be inserted
...
...
@@ -3453,31 +3453,6 @@ int tscProcessQueryRsp(SSqlObj *pSql) {
return
0
;
}
static
void
doDecompressPayload
(
SSqlCmd
*
pCmd
,
SSqlRes
*
pRes
,
int16_t
compressed
)
{
if
(
compressed
&&
pRes
->
numOfRows
>
0
)
{
SRetrieveMeterRsp
*
pRetrieve
=
(
SRetrieveMeterRsp
*
)
pRes
->
pRsp
;
int32_t
numOfTotalCols
=
pCmd
->
fieldsInfo
.
numOfOutputCols
+
pCmd
->
fieldsInfo
.
numOfHiddenCols
;
int32_t
rowSize
=
pCmd
->
fieldsInfo
.
pOffset
[
numOfTotalCols
-
1
]
+
pCmd
->
fieldsInfo
.
pFields
[
numOfTotalCols
-
1
].
bytes
;
// TODO handle the OOM problem
char
*
buf
=
malloc
(
rowSize
*
pRes
->
numOfRows
);
int32_t
payloadSize
=
pRes
->
rspLen
-
1
-
sizeof
(
SRetrieveMeterRsp
);
assert
(
payloadSize
>
0
);
int32_t
decompressedSize
=
tsDecompressString
(
pRetrieve
->
data
,
payloadSize
,
1
,
buf
,
rowSize
*
pRes
->
numOfRows
,
0
,
0
,
0
);
assert
(
decompressedSize
==
rowSize
*
pRes
->
numOfRows
);
pRes
->
pRsp
=
realloc
(
pRes
->
pRsp
,
pRes
->
rspLen
-
payloadSize
+
decompressedSize
);
memcpy
(
pRes
->
pRsp
+
sizeof
(
SRetrieveMeterRsp
),
buf
,
decompressedSize
);
free
(
buf
);
}
pRes
->
data
=
((
SRetrieveMeterRsp
*
)
pRes
->
pRsp
)
->
data
;
}
int
tscProcessRetrieveRspFromVnode
(
SSqlObj
*
pSql
)
{
SSqlRes
*
pRes
=
&
pSql
->
res
;
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
...
...
@@ -3490,9 +3465,7 @@ int tscProcessRetrieveRspFromVnode(SSqlObj *pSql) {
pRes
->
offset
=
htobe64
(
pRetrieve
->
offset
);
pRes
->
useconds
=
htobe64
(
pRetrieve
->
useconds
);
pRetrieve
->
compress
=
htons
(
pRetrieve
->
compress
);
doDecompressPayload
(
pCmd
,
pRes
,
pRetrieve
->
compress
);
pRes
->
data
=
pRetrieve
->
data
;
tscSetResultPointer
(
pCmd
,
pRes
);
pRes
->
row
=
0
;
...
...
src/client/src/tscSql.c
浏览文件 @
574f9d4c
...
...
@@ -246,7 +246,12 @@ int taos_query_imp(STscObj* pObj, SSqlObj* pSql) {
tscDoQuery
(
pSql
);
}
if
(
pRes
->
code
==
TSDB_CODE_SUCCESS
)
{
tscTrace
(
"%p SQL result:%d, %s pObj:%p"
,
pSql
,
pRes
->
code
,
taos_errstr
(
pObj
),
pObj
);
}
else
{
tscError
(
"%p SQL result:%d, %s pObj:%p"
,
pSql
,
pRes
->
code
,
taos_errstr
(
pObj
),
pObj
);
}
if
(
pRes
->
code
!=
TSDB_CODE_SUCCESS
)
{
tscFreeSqlObjPartial
(
pSql
);
}
...
...
@@ -266,8 +271,9 @@ int taos_query(TAOS *taos, const char *sqlstr) {
size_t
sqlLen
=
strlen
(
sqlstr
);
if
(
sqlLen
>
TSDB_MAX_SQL_LEN
)
{
tscError
(
"%p sql too long"
,
pSql
);
pRes
->
code
=
TSDB_CODE_INVALID_SQL
;
pRes
->
code
=
tscInvalidSQLErrMsg
(
pSql
->
cmd
.
payload
,
"sql too long"
,
NULL
);
// set the additional error msg for invalid sql
tscError
(
"%p SQL result:%d, %s pObj:%p"
,
pSql
,
pRes
->
code
,
taos_errstr
(
taos
),
pObj
);
return
pRes
->
code
;
}
...
...
@@ -276,8 +282,9 @@ int taos_query(TAOS *taos, const char *sqlstr) {
void
*
sql
=
realloc
(
pSql
->
sqlstr
,
sqlLen
+
1
);
if
(
sql
==
NULL
)
{
pRes
->
code
=
TSDB_CODE_CLI_OUT_OF_MEMORY
;
tscError
(
"%p failed to malloc sql string buffer"
,
pSql
);
tscTrace
(
"%p SQL result:%d, %s pObj:%p"
,
pSql
,
pRes
->
code
,
taos_errstr
(
taos
),
pObj
);
tscError
(
"%p failed to malloc sql string buffer, reason:%s"
,
pSql
,
strerror
(
errno
));
tscError
(
"%p SQL result:%d, %s pObj:%p"
,
pSql
,
pRes
->
code
,
taos_errstr
(
taos
),
pObj
);
return
pRes
->
code
;
}
...
...
@@ -777,9 +784,9 @@ int taos_errno(TAOS *taos) {
}
char
*
taos_errstr
(
TAOS
*
taos
)
{
STscObj
*
pObj
=
(
STscObj
*
)
taos
;
u
nsigned
char
code
;
char
temp
[
256
]
=
{
0
};
STscObj
*
pObj
=
(
STscObj
*
)
taos
;
u
int8_t
code
;
//
char temp[256] = {0};
if
(
pObj
==
NULL
||
pObj
->
signature
!=
pObj
)
return
tsError
[
globalCode
];
...
...
@@ -788,9 +795,10 @@ char *taos_errstr(TAOS *taos) {
else
code
=
pObj
->
pSql
->
res
.
code
;
// for invalid sql, additional information is attached to explain why the sql is invalid
if
(
code
==
TSDB_CODE_INVALID_SQL
)
{
snprintf
(
temp
,
tListLen
(
temp
),
"invalid SQL: %s"
,
pObj
->
pSql
->
cmd
.
payload
);
strcpy
(
pObj
->
pSql
->
cmd
.
payload
,
temp
);
//
snprintf(temp, tListLen(temp), "invalid SQL: %s", pObj->pSql->cmd.payload);
//
strcpy(pObj->pSql->cmd.payload, temp);
return
pObj
->
pSql
->
cmd
.
payload
;
}
else
{
return
tsError
[
code
];
...
...
src/client/src/tscUtil.c
浏览文件 @
574f9d4c
...
...
@@ -1294,8 +1294,7 @@ int32_t tscValidateName(SSQLToken* pToken) {
// re-build the whole name string
if
(
pStr
[
firstPartLen
]
==
TS_PATH_DELIMITER
[
0
])
{
// first part do not have quote
// do nothing
// first part do not have quote do nothing
}
else
{
pStr
[
firstPartLen
]
=
TS_PATH_DELIMITER
[
0
];
memmove
(
&
pStr
[
firstPartLen
+
1
],
pToken
->
z
,
pToken
->
n
);
...
...
@@ -1842,5 +1841,30 @@ bool tscIsUpdateQuery(STscObj* pObj) {
SSqlCmd
*
pCmd
=
&
pObj
->
pSql
->
cmd
;
return
((
pCmd
->
command
>=
TSDB_SQL_INSERT
&&
pCmd
->
command
<=
TSDB_SQL_DROP_DNODE
)
||
TSDB_SQL_USE_DB
==
pCmd
->
command
)
?
1
:
0
;
}
int32_t
tscInvalidSQLErrMsg
(
char
*
msg
,
const
char
*
additionalInfo
,
const
char
*
sql
)
{
const
char
*
msgFormat1
=
"invalid SQL: %s"
;
const
char
*
msgFormat2
=
"invalid SQL: syntax error near
\"
%s
\"
(%s)"
;
const
char
*
msgFormat3
=
"invalid SQL: syntax error near
\"
%s
\"
"
;
const
int32_t
BACKWARD_CHAR_STEP
=
0
;
if
(
sql
==
NULL
)
{
assert
(
additionalInfo
!=
NULL
);
sprintf
(
msg
,
msgFormat1
,
additionalInfo
);
return
TSDB_CODE_INVALID_SQL
;
}
char
buf
[
64
]
=
{
0
};
// only extract part of sql string
strncpy
(
buf
,
(
sql
-
BACKWARD_CHAR_STEP
),
tListLen
(
buf
)
-
1
);
if
(
additionalInfo
!=
NULL
)
{
sprintf
(
msg
,
msgFormat2
,
buf
,
additionalInfo
);
}
else
{
sprintf
(
msg
,
msgFormat3
,
buf
);
// no additional information for invalid sql error
}
return
TSDB_CODE_INVALID_SQL
;
}
src/inc/taosmsg.h
浏览文件 @
574f9d4c
...
...
@@ -568,7 +568,6 @@ typedef struct {
typedef
struct
{
int32_t
numOfRows
;
int16_t
precision
;
int16_t
compress
;
int64_t
offset
;
// updated offset value for multi-vnode projection query
int64_t
useconds
;
char
data
[];
...
...
src/system/detail/inc/vnode.h
浏览文件 @
574f9d4c
...
...
@@ -353,7 +353,7 @@ bool vnodeIsValidVnodeCfg(SVnodeCfg *pCfg);
int32_t
vnodeGetResultSize
(
void
*
handle
,
int32_t
*
numOfRows
);
int32_t
vnodeCopyQueryResultToMsg
(
void
*
handle
,
char
*
data
,
int32_t
numOfRows
,
int32_t
*
size
);
int32_t
vnodeCopyQueryResultToMsg
(
void
*
handle
,
char
*
data
,
int32_t
numOfRows
);
int64_t
vnodeGetOffsetVal
(
void
*
thandle
);
...
...
src/system/detail/src/vnodeQueryImpl.c
浏览文件 @
574f9d4c
...
...
@@ -6943,37 +6943,19 @@ static int32_t resultInterpolate(SQInfo *pQInfo, tFilePage **data, tFilePage **p
return
numOfRes
;
}
static
void
doCopyQueryResultToMsg
(
SQInfo
*
pQInfo
,
int32_t
numOfRows
,
char
*
data
,
int32_t
*
size
)
{
static
void
doCopyQueryResultToMsg
(
SQInfo
*
pQInfo
,
int32_t
numOfRows
,
char
*
data
)
{
SMeterObj
*
pObj
=
pQInfo
->
pObj
;
SQuery
*
pQuery
=
&
pQInfo
->
query
;
int
tnumOfRows
=
vnodeList
[
pObj
->
vnode
].
cfg
.
rowsInFileBlock
;
int32_t
dataSize
=
pQInfo
->
query
.
rowSize
*
numOfRows
;
if
(
dataSize
>=
tsCompressMsgSize
&&
tsCompressMsgSize
>
0
)
{
char
*
compBuf
=
malloc
((
size_t
)
dataSize
);
// for metric query, bufIndex always be 0.
char
*
d
=
compBuf
;
for
(
int32_t
col
=
0
;
col
<
pQuery
->
numOfOutputCols
;
++
col
)
{
// pQInfo->bufIndex == 0
int32_t
bytes
=
pQuery
->
pSelectExpr
[
col
].
resBytes
;
memmove
(
d
,
pQuery
->
sdata
[
col
]
->
data
+
bytes
*
tnumOfRows
*
pQInfo
->
bufIndex
,
bytes
*
numOfRows
);
d
+=
bytes
*
numOfRows
;
}
*
size
=
tsCompressString
(
compBuf
,
dataSize
,
1
,
data
,
dataSize
+
EXTRA_BYTES
,
0
,
0
,
0
);
dTrace
(
"QInfo:%p compress rsp msg, before:%d, after:%d"
,
pQInfo
,
dataSize
,
*
size
);
free
(
compBuf
);
}
else
{
// for metric query, bufIndex always be 0.
for
(
int32_t
col
=
0
;
col
<
pQuery
->
numOfOutputCols
;
++
col
)
{
// pQInfo->bufIndex == 0
int32_t
bytes
=
pQuery
->
pSelectExpr
[
col
].
resBytes
;
memmove
(
data
,
pQuery
->
sdata
[
col
]
->
data
+
bytes
*
tnumOfRows
*
pQInfo
->
bufIndex
,
bytes
*
numOfRows
);
data
+=
bytes
*
numOfRows
;
}
}
}
/**
...
...
@@ -6987,7 +6969,7 @@ static void doCopyQueryResultToMsg(SQInfo *pQInfo, int32_t numOfRows, char *data
* @param numOfRows the number of rows that are not returned in current retrieve
* @return
*/
int32_t
vnodeCopyQueryResultToMsg
(
void
*
handle
,
char
*
data
,
int32_t
numOfRows
,
int32_t
*
size
)
{
int32_t
vnodeCopyQueryResultToMsg
(
void
*
handle
,
char
*
data
,
int32_t
numOfRows
)
{
SQInfo
*
pQInfo
=
(
SQInfo
*
)
handle
;
SQuery
*
pQuery
=
&
pQInfo
->
query
;
...
...
@@ -7000,7 +6982,7 @@ int32_t vnodeCopyQueryResultToMsg(void *handle, char *data, int32_t numOfRows, i
// make sure file exist
if
(
VALIDFD
(
fd
))
{
size_t
s
=
lseek
(
fd
,
0
,
SEEK_END
);
dTrace
(
"QInfo:%p ts comp data return, file:%s, size:%l
d"
,
pQInfo
,
pQuery
->
sdata
[
0
]
->
data
,
size
);
dTrace
(
"QInfo:%p ts comp data return, file:%s, size:%l
ld"
,
pQInfo
,
pQuery
->
sdata
[
0
]
->
data
,
s
);
lseek
(
fd
,
0
,
SEEK_SET
);
read
(
fd
,
data
,
s
);
...
...
@@ -7012,7 +6994,7 @@ int32_t vnodeCopyQueryResultToMsg(void *handle, char *data, int32_t numOfRows, i
pQuery
->
sdata
[
0
]
->
data
,
strerror
(
errno
));
}
}
else
{
doCopyQueryResultToMsg
(
pQInfo
,
numOfRows
,
data
,
size
);
doCopyQueryResultToMsg
(
pQInfo
,
numOfRows
,
data
);
}
return
numOfRows
;
...
...
src/system/detail/src/vnodeRead.c
浏览文件 @
574f9d4c
...
...
@@ -850,7 +850,7 @@ int vnodeSaveQueryResult(void *handle, char *data, int32_t *size) {
// the remained number of retrieved rows, not the interpolated result
int
numOfRows
=
pQInfo
->
pointsRead
-
pQInfo
->
pointsReturned
;
int32_t
numOfFinal
=
vnodeCopyQueryResultToMsg
(
pQInfo
,
data
,
numOfRows
,
size
);
int32_t
numOfFinal
=
vnodeCopyQueryResultToMsg
(
pQInfo
,
data
,
numOfRows
);
pQInfo
->
pointsReturned
+=
numOfFinal
;
dTrace
(
"QInfo:%p %d are returned, totalReturned:%d totalRead:%d"
,
pQInfo
,
numOfFinal
,
pQInfo
->
pointsReturned
,
...
...
@@ -862,12 +862,9 @@ int vnodeSaveQueryResult(void *handle, char *data, int32_t *size) {
uint64_t
oldSignature
=
TSDB_QINFO_SET_QUERY_FLAG
(
pQInfo
);
/*
* If SQInfo has been released, the value of signature cannot be equalled to
* the address of pQInfo, since in release function, the original value has
* been
* destroyed. However, this memory area may be reused by another function.
* It may be 0 or any value, but it is rarely still be equalled to the address
* of SQInfo.
* If SQInfo has been released, the value of signature cannot be equalled to the address of pQInfo,
* since in release function, the original value has been destroyed. However, this memory area may be reused
* by another function. It may be 0 or any value, but it is rarely still be equalled to the address of SQInfo.
*/
if
(
oldSignature
==
0
||
oldSignature
!=
(
uint64_t
)
pQInfo
)
{
dTrace
(
"%p freed or killed, old sig:%p abort query"
,
pQInfo
,
oldSignature
);
...
...
src/system/detail/src/vnodeShell.c
浏览文件 @
574f9d4c
...
...
@@ -452,11 +452,7 @@ void vnodeExecuteRetrieveReq(SSchedMsg *pSched) {
pMsg
=
pRsp
->
data
;
if
(
numOfRows
>
0
&&
code
==
TSDB_CODE_SUCCESS
)
{
int32_t
oldSize
=
size
;
vnodeSaveQueryResult
((
void
*
)(
pRetrieve
->
qhandle
),
pRsp
->
data
,
&
size
);
if
(
oldSize
>
size
)
{
pRsp
->
compress
=
htons
(
1
);
// denote that the response msg is compressed
}
}
pMsg
+=
size
;
...
...
@@ -573,6 +569,7 @@ int vnodeProcessShellSubmitRequest(char *pMsg, int msgLen, SShellObj *pObj) {
int
sversion
=
htonl
(
pBlocks
->
sversion
);
if
(
pSubmit
->
import
)
{
dTrace
(
"start to import data"
);
code
=
vnodeImportPoints
(
pMeterObj
,
(
char
*
)
&
(
pBlocks
->
numOfRows
),
subMsgLen
,
TSDB_DATA_SOURCE_SHELL
,
pObj
,
sversion
,
&
numOfPoints
,
now
);
}
else
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录