Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
4d07077b
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
4d07077b
编写于
5月 14, 2022
作者:
X
Xiaoyu Wang
提交者:
GitHub
5月 14, 2022
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #12477 from taosdata/feature/3.0_wxy
fix: some problems of parser and planner
上级
b14e0e21
71c63a9b
变更
18
隐藏空白更改
内联
并排
Showing
18 changed file
with
389 addition
and
120 deletion
+389
-120
include/common/ttime.h
include/common/ttime.h
+8
-7
include/libs/qcom/query.h
include/libs/qcom/query.h
+71
-48
include/util/taoserror.h
include/util/taoserror.h
+2
-0
source/client/src/clientImpl.c
source/client/src/clientImpl.c
+2
-1
source/libs/nodes/src/nodesCodeFuncs.c
source/libs/nodes/src/nodesCodeFuncs.c
+162
-42
source/libs/parser/src/parAstCreater.c
source/libs/parser/src/parAstCreater.c
+17
-0
source/libs/parser/src/parAuthenticator.c
source/libs/parser/src/parAuthenticator.c
+11
-2
source/libs/parser/src/parCalcConst.c
source/libs/parser/src/parCalcConst.c
+2
-2
source/libs/parser/src/parTranslater.c
source/libs/parser/src/parTranslater.c
+30
-5
source/libs/parser/src/parUtil.c
source/libs/parser/src/parUtil.c
+4
-0
source/libs/parser/test/parSelectTest.cpp
source/libs/parser/test/parSelectTest.cpp
+5
-3
source/libs/planner/src/planOptimizer.c
source/libs/planner/src/planOptimizer.c
+7
-3
source/libs/planner/src/planPhysiCreater.c
source/libs/planner/src/planPhysiCreater.c
+18
-0
source/libs/planner/test/planJoinTest.cpp
source/libs/planner/test/planJoinTest.cpp
+10
-4
source/libs/planner/test/planSubqueryTest.cpp
source/libs/planner/test/planSubqueryTest.cpp
+6
-2
source/libs/planner/test/planTestMain.cpp
source/libs/planner/test/planTestMain.cpp
+31
-1
source/libs/planner/test/planTestUtil.cpp
source/libs/planner/test/planTestUtil.cpp
+1
-0
source/libs/planner/test/planTestUtil.h
source/libs/planner/test/planTestUtil.h
+2
-0
未找到文件。
include/common/ttime.h
浏览文件 @
4d07077b
...
...
@@ -59,10 +59,11 @@ static FORCE_INLINE int64_t taosGetTimestamp(int32_t precision) {
* precision == TSDB_TIME_PRECISION_NANO, it returns timestamp in nanosecond.
*/
static
FORCE_INLINE
int64_t
taosGetTimestampToday
(
int32_t
precision
)
{
int64_t
factor
=
(
precision
==
TSDB_TIME_PRECISION_MILLI
)
?
1000
:
(
precision
==
TSDB_TIME_PRECISION_MICRO
)
?
1000000
:
1000000000
;
time_t
t
=
taosTime
(
NULL
);
struct
tm
*
tm
=
taosLocalTime
(
&
t
,
NULL
);
int64_t
factor
=
(
precision
==
TSDB_TIME_PRECISION_MILLI
)
?
1000
:
(
precision
==
TSDB_TIME_PRECISION_MICRO
)
?
1000000
:
1000000000
;
time_t
t
=
taosTime
(
NULL
);
struct
tm
*
tm
=
taosLocalTime
(
&
t
,
NULL
);
tm
->
tm_hour
=
0
;
tm
->
tm_min
=
0
;
tm
->
tm_sec
=
0
;
...
...
@@ -79,13 +80,13 @@ int32_t parseNatualDuration(const char* token, int32_t tokenLen, int64_t* durati
int32_t
taosParseTime
(
const
char
*
timestr
,
int64_t
*
time
,
int32_t
len
,
int32_t
timePrec
,
int8_t
dayligth
);
void
deltaToUtcInitOnce
();
char
getPrecisionUnit
(
int32_t
precision
);
char
getPrecisionUnit
(
int32_t
precision
);
int64_t
convertTimePrecision
(
int64_t
time
,
int32_t
fromPrecision
,
int32_t
toPrecision
);
int64_t
convertTimeFromPrecisionToUnit
(
int64_t
time
,
int32_t
fromPrecision
,
char
toUnit
);
int32_t
convertStringToTimestamp
(
int16_t
type
,
char
*
inputData
,
int64_t
timePrec
,
int64_t
*
timeVal
);
int32_t
convertStringToTimestamp
(
int16_t
type
,
char
*
inputData
,
int64_t
timePrec
,
int64_t
*
timeVal
);
void
taosFormatUtcTime
(
char
*
buf
,
int32_t
bufLen
,
int64_t
time
,
int32_t
precision
);
void
taosFormatUtcTime
(
char
*
buf
,
int32_t
bufLen
,
int64_t
time
,
int32_t
precision
);
#ifdef __cplusplus
}
...
...
include/libs/qcom/query.h
浏览文件 @
4d07077b
...
...
@@ -51,14 +51,12 @@ typedef struct STableComInfo {
}
STableComInfo
;
typedef
struct
SIndexMeta
{
#ifdef WINDOWS
size_t
avoidCompilationErrors
;
#endif
}
SIndexMeta
;
/*
* ASSERT(sizeof(SCTableMeta) == 24)
* ASSERT(tableType == TSDB_CHILD_TABLE)
...
...
@@ -95,7 +93,7 @@ typedef struct SDBVgInfo {
int32_t
vgVersion
;
int8_t
hashMethod
;
int32_t
numOfTable
;
// DB's table num, unit is TSDB_TABLE_NUM_UNIT
SHashObj
*
vgHash
;
//
key:vgId, value:SVgroupInfo
SHashObj
*
vgHash
;
//
key:vgId, value:SVgroupInfo
}
SDBVgInfo
;
typedef
struct
SUseDbOutput
{
...
...
@@ -135,7 +133,7 @@ typedef struct SMsgSendInfo {
}
SMsgSendInfo
;
typedef
struct
SQueryNodeStat
{
int32_t
tableNum
;
// vg table number, unit is TSDB_TABLE_NUM_UNIT
int32_t
tableNum
;
// vg table number, unit is TSDB_TABLE_NUM_UNIT
}
SQueryNodeStat
;
int32_t
initTaskQueue
();
...
...
@@ -172,7 +170,7 @@ const SSchema* tGetTbnameColumnSchema();
bool
tIsValidSchema
(
struct
SSchema
*
pSchema
,
int32_t
numOfCols
,
int32_t
numOfTags
);
int32_t
queryCreateTableMetaFromMsg
(
STableMetaRsp
*
msg
,
bool
isSuperTable
,
STableMeta
**
pMeta
);
char
*
jobTaskStatusStr
(
int32_t
status
);
char
*
jobTaskStatusStr
(
int32_t
status
);
SSchema
createSchema
(
int8_t
type
,
int32_t
bytes
,
col_id_t
colId
,
const
char
*
name
);
...
...
@@ -184,62 +182,87 @@ extern int32_t (*queryProcessMsgRsp[TDMT_MAX])(void* output, char* msg, int32_t
#define SET_META_TYPE_TABLE(t) (t) = META_TYPE_TABLE
#define SET_META_TYPE_BOTH_TABLE(t) (t) = META_TYPE_BOTH_TABLE
#define NEED_CLIENT_RM_TBLMETA_ERROR(_code) ((_code) == TSDB_CODE_PAR_TABLE_NOT_EXIST || (_code) == TSDB_CODE_VND_TB_NOT_EXIST)
#define NEED_CLIENT_REFRESH_VG_ERROR(_code) ((_code) == TSDB_CODE_VND_HASH_MISMATCH || (_code) == TSDB_CODE_VND_INVALID_VGROUP_ID)
#define NEED_CLIENT_RM_TBLMETA_ERROR(_code) \
((_code) == TSDB_CODE_PAR_TABLE_NOT_EXIST || (_code) == TSDB_CODE_VND_TB_NOT_EXIST)
#define NEED_CLIENT_REFRESH_VG_ERROR(_code) \
((_code) == TSDB_CODE_VND_HASH_MISMATCH || (_code) == TSDB_CODE_VND_INVALID_VGROUP_ID)
#define NEED_CLIENT_REFRESH_TBLMETA_ERROR(_code) ((_code) == TSDB_CODE_TDB_TABLE_RECREATED)
#define NEED_CLIENT_HANDLE_ERROR(_code) (NEED_CLIENT_RM_TBLMETA_ERROR(_code) || NEED_CLIENT_REFRESH_VG_ERROR(_code) || NEED_CLIENT_REFRESH_TBLMETA_ERROR(_code))
#define NEED_CLIENT_HANDLE_ERROR(_code) \
(NEED_CLIENT_RM_TBLMETA_ERROR(_code) || NEED_CLIENT_REFRESH_VG_ERROR(_code) || \
NEED_CLIENT_REFRESH_TBLMETA_ERROR(_code))
#define NEED_SCHEDULER_RETRY_ERROR(_code) ((_code) == TSDB_CODE_RPC_REDIRECT || (_code) == TSDB_CODE_RPC_NETWORK_UNAVAIL)
#define NEED_SCHEDULER_RETRY_ERROR(_code) \
((_code) == TSDB_CODE_RPC_REDIRECT || (_code) == TSDB_CODE_RPC_NETWORK_UNAVAIL)
#define REQUEST_MAX_TRY_TIMES 5
#define qFatal(...) \
do { \
if (qDebugFlag & DEBUG_FATAL) { \
taosPrintLog("QRY FATAL ", DEBUG_FATAL, qDebugFlag, __VA_ARGS__); \
} \
#define qFatal(...)
\
do {
\
if (qDebugFlag & DEBUG_FATAL) {
\
taosPrintLog("QRY FATAL ", DEBUG_FATAL,
tsLogEmbedded ? 255 :
qDebugFlag, __VA_ARGS__); \
}
\
} while (0)
#define qError(...) \
do { \
if (qDebugFlag & DEBUG_ERROR) { \
taosPrintLog("QRY ERROR ", DEBUG_ERROR, qDebugFlag, __VA_ARGS__); \
} \
#define qError(...)
\
do {
\
if (qDebugFlag & DEBUG_ERROR) {
\
taosPrintLog("QRY ERROR ", DEBUG_ERROR,
tsLogEmbedded ? 255 :
qDebugFlag, __VA_ARGS__); \
}
\
} while (0)
#define qWarn(...) \
do { \
if (qDebugFlag & DEBUG_WARN) { \
taosPrintLog("QRY WARN ", DEBUG_WARN, qDebugFlag, __VA_ARGS__); \
} \
#define qWarn(...)
\
do {
\
if (qDebugFlag & DEBUG_WARN) {
\
taosPrintLog("QRY WARN ", DEBUG_WARN,
tsLogEmbedded ? 255 :
qDebugFlag, __VA_ARGS__); \
}
\
} while (0)
#define qInfo(...) \
do { \
if (qDebugFlag & DEBUG_INFO) { \
taosPrintLog("QRY ", DEBUG_INFO, qDebugFlag, __VA_ARGS__); \
} \
#define qInfo(...)
\
do {
\
if (qDebugFlag & DEBUG_INFO) {
\
taosPrintLog("QRY ", DEBUG_INFO,
tsLogEmbedded ? 255 :
qDebugFlag, __VA_ARGS__); \
}
\
} while (0)
#define qDebug(...) \
do { \
if (qDebugFlag & DEBUG_DEBUG) { \
taosPrintLog("QRY ", DEBUG_DEBUG, qDebugFlag, __VA_ARGS__); \
} \
#define qDebug(...)
\
do {
\
if (qDebugFlag & DEBUG_DEBUG) {
\
taosPrintLog("QRY ", DEBUG_DEBUG,
tsLogEmbedded ? 255 :
qDebugFlag, __VA_ARGS__); \
}
\
} while (0)
#define qTrace(...) \
do { \
if (qDebugFlag & DEBUG_TRACE) { \
taosPrintLog("QRY ", DEBUG_TRACE, qDebugFlag, __VA_ARGS__); \
} \
#define qTrace(...)
\
do {
\
if (qDebugFlag & DEBUG_TRACE) {
\
taosPrintLog("QRY ", DEBUG_TRACE,
tsLogEmbedded ? 255 :
qDebugFlag, __VA_ARGS__); \
}
\
} while (0)
#define qDebugL(...) \
do { \
if (qDebugFlag & DEBUG_DEBUG) { \
taosPrintLongString("QRY ", DEBUG_DEBUG, qDebugFlag, __VA_ARGS__); \
} \
#define qDebugL(...)
\
do {
\
if (qDebugFlag & DEBUG_DEBUG) {
\
taosPrintLongString("QRY ", DEBUG_DEBUG,
tsLogEmbedded ? 255 :
qDebugFlag, __VA_ARGS__); \
}
\
} while (0)
#define QRY_ERR_RET(c) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { terrno = _code; return _code; } } while (0)
#define QRY_RET(c) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { terrno = _code; } return _code; } while (0)
#define QRY_ERR_JRET(c) do { code = c; if (code != TSDB_CODE_SUCCESS) { terrno = code; goto _return; } } while (0)
#define QRY_ERR_RET(c) \
do { \
int32_t _code = c; \
if (_code != TSDB_CODE_SUCCESS) { \
terrno = _code; \
return _code; \
} \
} while (0)
#define QRY_RET(c) \
do { \
int32_t _code = c; \
if (_code != TSDB_CODE_SUCCESS) { \
terrno = _code; \
} \
return _code; \
} while (0)
#define QRY_ERR_JRET(c) \
do { \
code = c; \
if (code != TSDB_CODE_SUCCESS) { \
terrno = code; \
goto _return; \
} \
} while (0)
#ifdef __cplusplus
}
...
...
include/util/taoserror.h
浏览文件 @
4d07077b
...
...
@@ -636,6 +636,8 @@ int32_t* taosGetErrno();
#define TSDB_CODE_PAR_PERMISSION_DENIED TAOS_DEF_ERROR_CODE(0, 0x2644)
#define TSDB_CODE_PAR_INVALID_STREAM_QUERY TAOS_DEF_ERROR_CODE(0, 0x2645)
#define TSDB_CODE_PAR_INVALID_INTERNAL_PK TAOS_DEF_ERROR_CODE(0, 0x2646)
#define TSDB_CODE_PAR_INVALID_TIMELINE_FUNC TAOS_DEF_ERROR_CODE(0, 0x2647)
#define TSDB_CODE_PAR_INVALID_PASSWD TAOS_DEF_ERROR_CODE(0, 0x2648)
//planner
#define TSDB_CODE_PLAN_INTERNAL_ERROR TAOS_DEF_ERROR_CODE(0, 0x2700)
...
...
source/client/src/clientImpl.c
浏览文件 @
4d07077b
...
...
@@ -172,7 +172,8 @@ int32_t parseSql(SRequestObj* pRequest, bool topicQuery, SQuery** pQuery, SStmtC
.
msgLen
=
ERROR_MSG_BUF_DEFAULT_SIZE
,
.
pTransporter
=
pTscObj
->
pAppInfo
->
pTransporter
,
.
pStmtCb
=
pStmtCb
,
.
pUser
=
pTscObj
->
user
};
.
pUser
=
pTscObj
->
user
,
.
isSuperUser
=
(
0
==
strcmp
(
pTscObj
->
user
,
TSDB_DEFAULT_USER
))};
cxt
.
mgmtEpSet
=
getEpSet_s
(
&
pTscObj
->
pAppInfo
->
mgmtEp
);
int32_t
code
=
catalogGetHandle
(
pTscObj
->
pAppInfo
->
clusterId
,
&
cxt
.
pCatalog
);
...
...
source/libs/nodes/src/nodesCodeFuncs.c
浏览文件 @
4d07077b
...
...
@@ -318,15 +318,19 @@ static int32_t jsonToTableComInfo(const SJson* pJson, void* pObj) {
STableComInfo
*
pNode
=
(
STableComInfo
*
)
pObj
;
int32_t
code
;
tjsonGetNumberValue
(
pJson
,
jkTableComInfoNumOfTags
,
pNode
->
numOfTags
,
code
);;
tjsonGetNumberValue
(
pJson
,
jkTableComInfoNumOfTags
,
pNode
->
numOfTags
,
code
);
;
if
(
TSDB_CODE_SUCCESS
==
code
)
{
tjsonGetNumberValue
(
pJson
,
jkTableComInfoPrecision
,
pNode
->
precision
,
code
);;
tjsonGetNumberValue
(
pJson
,
jkTableComInfoPrecision
,
pNode
->
precision
,
code
);
;
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
tjsonGetNumberValue
(
pJson
,
jkTableComInfoNumOfColumns
,
pNode
->
numOfColumns
,
code
);;
tjsonGetNumberValue
(
pJson
,
jkTableComInfoNumOfColumns
,
pNode
->
numOfColumns
,
code
);
;
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
tjsonGetNumberValue
(
pJson
,
jkTableComInfoRowSize
,
pNode
->
rowSize
,
code
);;
tjsonGetNumberValue
(
pJson
,
jkTableComInfoRowSize
,
pNode
->
rowSize
,
code
);
;
}
return
code
;
...
...
@@ -358,12 +362,15 @@ static int32_t jsonToSchema(const SJson* pJson, void* pObj) {
SSchema
*
pNode
=
(
SSchema
*
)
pObj
;
int32_t
code
;
tjsonGetNumberValue
(
pJson
,
jkSchemaType
,
pNode
->
type
,
code
);;
tjsonGetNumberValue
(
pJson
,
jkSchemaType
,
pNode
->
type
,
code
);
;
if
(
TSDB_CODE_SUCCESS
==
code
)
{
tjsonGetNumberValue
(
pJson
,
jkSchemaColId
,
pNode
->
colId
,
code
);;
tjsonGetNumberValue
(
pJson
,
jkSchemaColId
,
pNode
->
colId
,
code
);
;
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
tjsonGetNumberValue
(
pJson
,
jkSchemaBytes
,
pNode
->
bytes
,
code
);;
tjsonGetNumberValue
(
pJson
,
jkSchemaBytes
,
pNode
->
bytes
,
code
);
;
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
tjsonGetStringValue
(
pJson
,
jkSchemaName
,
pNode
->
name
);
...
...
@@ -415,21 +422,27 @@ static int32_t jsonToTableMeta(const SJson* pJson, void* pObj) {
STableMeta
*
pNode
=
(
STableMeta
*
)
pObj
;
int32_t
code
;
tjsonGetNumberValue
(
pJson
,
jkTableMetaVgId
,
pNode
->
vgId
,
code
);;
tjsonGetNumberValue
(
pJson
,
jkTableMetaVgId
,
pNode
->
vgId
,
code
);
;
if
(
TSDB_CODE_SUCCESS
==
code
)
{
tjsonGetNumberValue
(
pJson
,
jkTableMetaTableType
,
pNode
->
tableType
,
code
);;
tjsonGetNumberValue
(
pJson
,
jkTableMetaTableType
,
pNode
->
tableType
,
code
);
;
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
tjsonGetNumberValue
(
pJson
,
jkTableMetaUid
,
pNode
->
uid
,
code
);;
tjsonGetNumberValue
(
pJson
,
jkTableMetaUid
,
pNode
->
uid
,
code
);
;
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
tjsonGetNumberValue
(
pJson
,
jkTableMetaSuid
,
pNode
->
suid
,
code
);;
tjsonGetNumberValue
(
pJson
,
jkTableMetaSuid
,
pNode
->
suid
,
code
);
;
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
tjsonGetNumberValue
(
pJson
,
jkTableMetaSversion
,
pNode
->
sversion
,
code
);;
tjsonGetNumberValue
(
pJson
,
jkTableMetaSversion
,
pNode
->
sversion
,
code
);
;
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
tjsonGetNumberValue
(
pJson
,
jkTableMetaTversion
,
pNode
->
tversion
,
code
);;
tjsonGetNumberValue
(
pJson
,
jkTableMetaTversion
,
pNode
->
tversion
,
code
);
;
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
tjsonToObject
(
pJson
,
jkTableMetaComInfo
,
jsonToTableComInfo
,
&
pNode
->
tableInfo
);
...
...
@@ -605,7 +618,8 @@ static int32_t jsonToLogicFillNode(const SJson* pJson, void* pObj) {
int32_t
code
=
jsonToLogicPlanNode
(
pJson
,
pObj
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
tjsonGetNumberValue
(
pJson
,
jkFillLogicPlanMode
,
pNode
->
mode
,
code
);;
tjsonGetNumberValue
(
pJson
,
jkFillLogicPlanMode
,
pNode
->
mode
,
code
);
;
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
jsonToNodeObject
(
pJson
,
jkFillLogicPlanWStartTs
,
&
pNode
->
pWStartTs
);
...
...
@@ -881,7 +895,8 @@ static int32_t jsonToLogicSubplan(const SJson* pJson, void* pObj) {
code
=
jsonToNodeObject
(
pJson
,
jkLogicSubplanRootNode
,
(
SNode
**
)
&
pNode
->
pNode
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
tjsonGetNumberValue
(
pJson
,
jkLogicSubplanType
,
pNode
->
subplanType
,
code
);;
tjsonGetNumberValue
(
pJson
,
jkLogicSubplanType
,
pNode
->
subplanType
,
code
);
;
}
int32_t
objSize
=
0
;
if
(
TSDB_CODE_SUCCESS
==
code
)
{
...
...
@@ -1121,33 +1136,43 @@ static int32_t jsonToPhysiTableScanNode(const SJson* pJson, void* pObj) {
code
=
tjsonGetDoubleValue
(
pJson
,
jkTableScanPhysiPlanRatio
,
&
pNode
->
ratio
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
tjsonGetNumberValue
(
pJson
,
jkTableScanPhysiPlanDataRequired
,
pNode
->
dataRequired
,
code
);;
tjsonGetNumberValue
(
pJson
,
jkTableScanPhysiPlanDataRequired
,
pNode
->
dataRequired
,
code
);
;
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
jsonToNodeList
(
pJson
,
jkTableScanPhysiPlanDynamicScanFuncs
,
&
pNode
->
pDynamicScanFuncs
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
tjsonGetNumberValue
(
pJson
,
jkTableScanPhysiPlanInterval
,
pNode
->
interval
,
code
);;
tjsonGetNumberValue
(
pJson
,
jkTableScanPhysiPlanInterval
,
pNode
->
interval
,
code
);
;
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
tjsonGetNumberValue
(
pJson
,
jkTableScanPhysiPlanOffset
,
pNode
->
offset
,
code
);;
tjsonGetNumberValue
(
pJson
,
jkTableScanPhysiPlanOffset
,
pNode
->
offset
,
code
);
;
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
tjsonGetNumberValue
(
pJson
,
jkTableScanPhysiPlanSliding
,
pNode
->
sliding
,
code
);;
tjsonGetNumberValue
(
pJson
,
jkTableScanPhysiPlanSliding
,
pNode
->
sliding
,
code
);
;
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
tjsonGetNumberValue
(
pJson
,
jkTableScanPhysiPlanIntervalUnit
,
pNode
->
intervalUnit
,
code
);;
tjsonGetNumberValue
(
pJson
,
jkTableScanPhysiPlanIntervalUnit
,
pNode
->
intervalUnit
,
code
);
;
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
tjsonGetNumberValue
(
pJson
,
jkTableScanPhysiPlanSlidingUnit
,
pNode
->
slidingUnit
,
code
);;
tjsonGetNumberValue
(
pJson
,
jkTableScanPhysiPlanSlidingUnit
,
pNode
->
slidingUnit
,
code
);
;
}
return
code
;
}
static
int32_t
physiStreamScanNodeToJson
(
const
void
*
pObj
,
SJson
*
pJson
)
{
return
physiTableScanNodeToJson
(
pObj
,
pJson
);
}
static
int32_t
physiStreamScanNodeToJson
(
const
void
*
pObj
,
SJson
*
pJson
)
{
return
physiTableScanNodeToJson
(
pObj
,
pJson
);
}
static
int32_t
jsonToPhysiStreamScanNode
(
const
SJson
*
pJson
,
void
*
pObj
)
{
return
jsonToPhysiTableScanNode
(
pJson
,
pObj
);
}
static
int32_t
jsonToPhysiStreamScanNode
(
const
SJson
*
pJson
,
void
*
pObj
)
{
return
jsonToPhysiTableScanNode
(
pJson
,
pObj
);
}
static
const
char
*
jkSysTableScanPhysiPlanMnodeEpSet
=
"MnodeEpSet"
;
static
const
char
*
jkSysTableScanPhysiPlanShowRewrite
=
"ShowRewrite"
;
...
...
@@ -1181,7 +1206,8 @@ static int32_t jsonToPhysiSysTableScanNode(const SJson* pJson, void* pObj) {
code
=
tjsonGetBoolValue
(
pJson
,
jkSysTableScanPhysiPlanShowRewrite
,
&
pNode
->
showRewrite
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
tjsonGetNumberValue
(
pJson
,
jkSysTableScanPhysiPlanAccountId
,
pNode
->
accountId
,
code
);;
tjsonGetNumberValue
(
pJson
,
jkSysTableScanPhysiPlanAccountId
,
pNode
->
accountId
,
code
);
;
}
return
code
;
...
...
@@ -1265,7 +1291,8 @@ static int32_t jsonToPhysiJoinNode(const SJson* pJson, void* pObj) {
int32_t
code
=
jsonToPhysicPlanNode
(
pJson
,
pObj
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
tjsonGetNumberValue
(
pJson
,
jkJoinPhysiPlanJoinType
,
pNode
->
joinType
,
code
);;
tjsonGetNumberValue
(
pJson
,
jkJoinPhysiPlanJoinType
,
pNode
->
joinType
,
code
);
;
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
jsonToNodeObject
(
pJson
,
jkJoinPhysiPlanOnConditions
,
&
pNode
->
pOnConditions
);
...
...
@@ -1427,10 +1454,12 @@ static int32_t jsonToPhysiWindowNode(const SJson* pJson, void* pObj) {
code
=
jsonToNodeObject
(
pJson
,
jkWindowPhysiPlanTsPk
,
(
SNode
**
)
&
pNode
->
pTspk
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
tjsonGetNumberValue
(
pJson
,
jkWindowPhysiPlanTriggerType
,
pNode
->
triggerType
,
code
);;
tjsonGetNumberValue
(
pJson
,
jkWindowPhysiPlanTriggerType
,
pNode
->
triggerType
,
code
);
;
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
tjsonGetNumberValue
(
pJson
,
jkWindowPhysiPlanWatermark
,
pNode
->
watermark
,
code
);;
tjsonGetNumberValue
(
pJson
,
jkWindowPhysiPlanWatermark
,
pNode
->
watermark
,
code
);
;
}
return
code
;
...
...
@@ -1526,7 +1555,8 @@ static int32_t jsonToPhysiFillNode(const SJson* pJson, void* pObj) {
int32_t
code
=
jsonToPhysicPlanNode
(
pJson
,
pObj
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
tjsonGetNumberValue
(
pJson
,
jkFillPhysiPlanMode
,
pNode
->
mode
,
code
);;
tjsonGetNumberValue
(
pJson
,
jkFillPhysiPlanMode
,
pNode
->
mode
,
code
);
;
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
jsonToNodeObject
(
pJson
,
jkFillPhysiPlanWStartTs
,
&
pNode
->
pWStartTs
);
...
...
@@ -1565,7 +1595,8 @@ static int32_t jsonToPhysiSessionWindowNode(const SJson* pJson, void* pObj) {
int32_t
code
=
jsonToPhysiWindowNode
(
pJson
,
pObj
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
tjsonGetNumberValue
(
pJson
,
jkSessionWindowPhysiPlanGap
,
pNode
->
gap
,
code
);;
tjsonGetNumberValue
(
pJson
,
jkSessionWindowPhysiPlanGap
,
pNode
->
gap
,
code
);
;
}
return
code
;
...
...
@@ -1727,7 +1758,8 @@ static int32_t jsonToSubplan(const SJson* pJson, void* pObj) {
int32_t
code
=
tjsonToObject
(
pJson
,
jkSubplanId
,
jsonToSubplanId
,
&
pNode
->
id
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
tjsonGetNumberValue
(
pJson
,
jkSubplanType
,
pNode
->
subplanType
,
code
);;
tjsonGetNumberValue
(
pJson
,
jkSubplanType
,
pNode
->
subplanType
,
code
);
;
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
tjsonGetIntValue
(
pJson
,
jkSubplanMsgType
,
&
pNode
->
msgType
);
...
...
@@ -1917,7 +1949,8 @@ static int32_t jsonToColumnNode(const SJson* pJson, void* pObj) {
code
=
tjsonGetSmallIntValue
(
pJson
,
jkColumnColId
,
&
pNode
->
colId
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
tjsonGetNumberValue
(
pJson
,
jkColumnColType
,
pNode
->
colType
,
code
);;
tjsonGetNumberValue
(
pJson
,
jkColumnColType
,
pNode
->
colType
,
code
);
;
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
tjsonGetStringValue
(
pJson
,
jkColumnDbName
,
pNode
->
dbName
);
...
...
@@ -2171,7 +2204,8 @@ static int32_t jsonToOperatorNode(const SJson* pJson, void* pObj) {
int32_t
code
=
jsonToExprNode
(
pJson
,
pObj
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
tjsonGetNumberValue
(
pJson
,
jkOperatorType
,
pNode
->
opType
,
code
);;
tjsonGetNumberValue
(
pJson
,
jkOperatorType
,
pNode
->
opType
,
code
);
;
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
jsonToNodeObject
(
pJson
,
jkOperatorLeft
,
&
pNode
->
pLeft
);
...
...
@@ -2205,7 +2239,8 @@ static int32_t jsonToLogicConditionNode(const SJson* pJson, void* pObj) {
int32_t
code
=
jsonToExprNode
(
pJson
,
pObj
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
tjsonGetNumberValue
(
pJson
,
jkLogicCondType
,
pNode
->
condType
,
code
);;
tjsonGetNumberValue
(
pJson
,
jkLogicCondType
,
pNode
->
condType
,
code
);
;
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
jsonToNodeList
(
pJson
,
jkLogicCondParameters
,
&
pNode
->
pParameterList
);
...
...
@@ -2350,6 +2385,30 @@ static int32_t jsonToRealTableNode(const SJson* pJson, void* pObj) {
return
code
;
}
static
const
char
*
jkTempTableSubquery
=
"Subquery"
;
static
int32_t
tempTableNodeToJson
(
const
void
*
pObj
,
SJson
*
pJson
)
{
const
STempTableNode
*
pNode
=
(
const
STempTableNode
*
)
pObj
;
int32_t
code
=
tableNodeToJson
(
pObj
,
pJson
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
tjsonAddObject
(
pJson
,
jkTempTableSubquery
,
nodeToJson
,
pNode
->
pSubquery
);
}
return
code
;
}
static
int32_t
jsonToTempTableNode
(
const
SJson
*
pJson
,
void
*
pObj
)
{
STempTableNode
*
pNode
=
(
STempTableNode
*
)
pObj
;
int32_t
code
=
jsonToTableNode
(
pJson
,
pObj
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
jsonToNodeObject
(
pJson
,
jkTempTableSubquery
,
&
pNode
->
pSubquery
);
}
return
code
;
}
static
const
char
*
jkGroupingSetType
=
"GroupingSetType"
;
static
const
char
*
jkGroupingSetParameter
=
"Parameters"
;
...
...
@@ -2387,10 +2446,12 @@ static int32_t jsonToOrderByExprNode(const SJson* pJson, void* pObj) {
int32_t
code
=
jsonToNodeObject
(
pJson
,
jkOrderByExprExpr
,
&
pNode
->
pExpr
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
tjsonGetNumberValue
(
pJson
,
jkOrderByExprOrder
,
pNode
->
order
,
code
);;
tjsonGetNumberValue
(
pJson
,
jkOrderByExprOrder
,
pNode
->
order
,
code
);
;
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
tjsonGetNumberValue
(
pJson
,
jkOrderByExprNullOrder
,
pNode
->
nullOrder
,
code
);;
tjsonGetNumberValue
(
pJson
,
jkOrderByExprNullOrder
,
pNode
->
nullOrder
,
code
);
;
}
return
code
;
...
...
@@ -2497,7 +2558,8 @@ static int32_t jsonToFillNode(const SJson* pJson, void* pObj) {
SFillNode
*
pNode
=
(
SFillNode
*
)
pObj
;
int32_t
code
;
tjsonGetNumberValue
(
pJson
,
jkFillMode
,
pNode
->
mode
,
code
);;
tjsonGetNumberValue
(
pJson
,
jkFillMode
,
pNode
->
mode
,
code
);
;
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
jsonToNodeObject
(
pJson
,
jkFillValues
,
&
pNode
->
pValues
);
}
...
...
@@ -2663,6 +2725,60 @@ static int32_t jsonToDataBlockDescNode(const SJson* pJson, void* pObj) {
return
code
;
}
static
const
char
*
jkSetOperatorOpType
=
"OpType"
;
static
const
char
*
jkSetOperatorProjections
=
"Projections"
;
static
const
char
*
jkSetOperatorLeft
=
"Left"
;
static
const
char
*
jkSetOperatorRight
=
"Right"
;
static
const
char
*
jkSetOperatorOrderByList
=
"OrderByList"
;
static
const
char
*
jkSetOperatorLimit
=
"Limit"
;
static
int32_t
setOperatorToJson
(
const
void
*
pObj
,
SJson
*
pJson
)
{
const
SSetOperator
*
pNode
=
(
const
SSetOperator
*
)
pObj
;
int32_t
code
=
tjsonAddIntegerToObject
(
pJson
,
jkSetOperatorOpType
,
pNode
->
opType
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
nodeListToJson
(
pJson
,
jkSetOperatorProjections
,
pNode
->
pProjectionList
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
tjsonAddObject
(
pJson
,
jkSetOperatorLeft
,
nodeToJson
,
pNode
->
pLeft
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
tjsonAddObject
(
pJson
,
jkSetOperatorRight
,
nodeToJson
,
pNode
->
pRight
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
nodeListToJson
(
pJson
,
jkSetOperatorOrderByList
,
pNode
->
pOrderByList
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
tjsonAddObject
(
pJson
,
jkSetOperatorLimit
,
nodeToJson
,
pNode
->
pLimit
);
}
return
code
;
}
static
int32_t
jsonToSetOperator
(
const
SJson
*
pJson
,
void
*
pObj
)
{
SSetOperator
*
pNode
=
(
SSetOperator
*
)
pObj
;
int32_t
code
=
TSDB_CODE_SUCCESS
;
tjsonGetNumberValue
(
pJson
,
jkSetOperatorOpType
,
pNode
->
opType
,
code
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
jsonToNodeList
(
pJson
,
jkSetOperatorProjections
,
&
pNode
->
pProjectionList
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
jsonToNodeObject
(
pJson
,
jkSetOperatorLeft
,
&
pNode
->
pLeft
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
jsonToNodeObject
(
pJson
,
jkSetOperatorRight
,
&
pNode
->
pRight
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
jsonToNodeList
(
pJson
,
jkSetOperatorOrderByList
,
&
pNode
->
pOrderByList
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
jsonToNodeObject
(
pJson
,
jkSetOperatorLimit
,
&
pNode
->
pLimit
);
}
return
code
;
}
static
const
char
*
jkSelectStmtDistinct
=
"Distinct"
;
static
const
char
*
jkSelectStmtProjections
=
"Projections"
;
static
const
char
*
jkSelectStmtFrom
=
"From"
;
...
...
@@ -2677,7 +2793,7 @@ static const char* jkSelectStmtSlimit = "Slimit";
static
const
char
*
jkSelectStmtStmtName
=
"StmtName"
;
static
const
char
*
jkSelectStmtHasAggFuncs
=
"HasAggFuncs"
;
static
int32_t
selectStmtTo
j
son
(
const
void
*
pObj
,
SJson
*
pJson
)
{
static
int32_t
selectStmtTo
J
son
(
const
void
*
pObj
,
SJson
*
pJson
)
{
const
SSelectStmt
*
pNode
=
(
const
SSelectStmt
*
)
pObj
;
int32_t
code
=
tjsonAddBoolToObject
(
pJson
,
jkSelectStmtDistinct
,
pNode
->
isDistinct
);
...
...
@@ -2819,6 +2935,7 @@ static int32_t specificNodeToJson(const void* pObj, SJson* pJson) {
case
QUERY_NODE_REAL_TABLE
:
return
realTableNodeToJson
(
pObj
,
pJson
);
case
QUERY_NODE_TEMP_TABLE
:
return
tempTableNodeToJson
(
pObj
,
pJson
);
case
QUERY_NODE_JOIN_TABLE
:
break
;
case
QUERY_NODE_GROUPING_SET
:
...
...
@@ -2848,9 +2965,9 @@ static int32_t specificNodeToJson(const void* pObj, SJson* pJson) {
case
QUERY_NODE_DOWNSTREAM_SOURCE
:
return
downstreamSourceNodeToJson
(
pObj
,
pJson
);
case
QUERY_NODE_SET_OPERATOR
:
break
;
return
setOperatorToJson
(
pObj
,
pJson
)
;
case
QUERY_NODE_SELECT_STMT
:
return
selectStmtTo
j
son
(
pObj
,
pJson
);
return
selectStmtTo
J
son
(
pObj
,
pJson
);
case
QUERY_NODE_VNODE_MODIF_STMT
:
case
QUERY_NODE_CREATE_DATABASE_STMT
:
case
QUERY_NODE_CREATE_TABLE_STMT
:
...
...
@@ -2918,7 +3035,6 @@ static int32_t specificNodeToJson(const void* pObj, SJson* pJson) {
case
QUERY_NODE_PHYSICAL_PLAN
:
return
planToJson
(
pObj
,
pJson
);
default:
// assert(0);
break
;
}
nodesWarn
(
"specificNodeToJson unknown node = %s"
,
nodesNodeName
(
nodeType
(
pObj
)));
...
...
@@ -2939,6 +3055,8 @@ static int32_t jsonToSpecificNode(const SJson* pJson, void* pObj) {
return
jsonToFunctionNode
(
pJson
,
pObj
);
case
QUERY_NODE_REAL_TABLE
:
return
jsonToRealTableNode
(
pJson
,
pObj
);
case
QUERY_NODE_TEMP_TABLE
:
return
jsonToTempTableNode
(
pJson
,
pObj
);
case
QUERY_NODE_ORDER_BY_EXPR
:
return
jsonToOrderByExprNode
(
pJson
,
pObj
);
case
QUERY_NODE_INTERVAL_WINDOW
:
...
...
@@ -2955,6 +3073,8 @@ static int32_t jsonToSpecificNode(const SJson* pJson, void* pObj) {
return
jsonToSlotDescNode
(
pJson
,
pObj
);
case
QUERY_NODE_DOWNSTREAM_SOURCE
:
return
jsonToDownstreamSourceNode
(
pJson
,
pObj
);
case
QUERY_NODE_SET_OPERATOR
:
return
jsonToSetOperator
(
pJson
,
pObj
);
case
QUERY_NODE_SELECT_STMT
:
return
jsonToSelectStmt
(
pJson
,
pObj
);
case
QUERY_NODE_CREATE_TOPIC_STMT
:
...
...
@@ -3007,7 +3127,6 @@ static int32_t jsonToSpecificNode(const SJson* pJson, void* pObj) {
case
QUERY_NODE_PHYSICAL_PLAN
:
return
jsonToPlan
(
pJson
,
pObj
);
default:
assert
(
0
);
break
;
}
nodesWarn
(
"jsonToSpecificNode unknown node = %s"
,
nodesNodeName
(
nodeType
(
pObj
)));
...
...
@@ -3038,7 +3157,8 @@ static int32_t jsonToNode(const SJson* pJson, void* pObj) {
SNode
*
pNode
=
(
SNode
*
)
pObj
;
int32_t
code
;
tjsonGetNumberValue
(
pJson
,
jkNodeType
,
pNode
->
type
,
code
);;
tjsonGetNumberValue
(
pJson
,
jkNodeType
,
pNode
->
type
,
code
);
;
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
tjsonToObject
(
pJson
,
nodesNodeName
(
pNode
->
type
),
jsonToSpecificNode
,
pNode
);
if
(
TSDB_CODE_SUCCESS
!=
code
)
{
...
...
source/libs/parser/src/parAstCreater.c
浏览文件 @
4d07077b
...
...
@@ -14,6 +14,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <regex.h>
#include "parAst.h"
#include "parUtil.h"
#include "ttime.h"
...
...
@@ -76,6 +78,19 @@ static bool checkUserName(SAstCreateContext* pCxt, SToken* pUserName) {
return
TSDB_CODE_SUCCESS
==
pCxt
->
errCode
;
}
static
bool
invalidPassword
(
const
char
*
pPassword
)
{
regex_t
regex
;
if
(
regcomp
(
&
regex
,
"[ '
\"
`
\\
]"
,
REG_EXTENDED
|
REG_ICASE
)
!=
0
)
{
return
false
;
}
/* Execute regular expression */
int32_t
res
=
regexec
(
&
regex
,
pPassword
,
0
,
NULL
,
0
);
regfree
(
&
regex
);
return
0
==
res
;
}
static
bool
checkPassword
(
SAstCreateContext
*
pCxt
,
const
SToken
*
pPasswordToken
,
char
*
pPassword
)
{
if
(
NULL
==
pPasswordToken
)
{
pCxt
->
errCode
=
TSDB_CODE_PAR_SYNTAX_ERROR
;
...
...
@@ -86,6 +101,8 @@ static bool checkPassword(SAstCreateContext* pCxt, const SToken* pPasswordToken,
strdequote
(
pPassword
);
if
(
strtrim
(
pPassword
)
<=
0
)
{
pCxt
->
errCode
=
generateSyntaxErrMsg
(
&
pCxt
->
msgBuf
,
TSDB_CODE_PAR_PASSWD_EMPTY
);
}
else
if
(
invalidPassword
(
pPassword
))
{
pCxt
->
errCode
=
generateSyntaxErrMsg
(
&
pCxt
->
msgBuf
,
TSDB_CODE_PAR_INVALID_PASSWD
);
}
}
return
TSDB_CODE_SUCCESS
==
pCxt
->
errCode
;
...
...
source/libs/parser/src/parAuthenticator.c
浏览文件 @
4d07077b
...
...
@@ -65,13 +65,19 @@ static int32_t authSetOperator(SAuthCxt* pCxt, SSetOperator* pSetOper) {
return
code
;
}
static
int32_t
authDropUser
(
SAuthCxt
*
pCxt
,
SDropUserReq
*
pStmt
)
{
if
(
!
pCxt
->
pParseCxt
->
isSuperUser
||
0
==
strcmp
(
pStmt
->
user
,
TSDB_DEFAULT_USER
))
{
return
TSDB_CODE_PAR_PERMISSION_DENIED
;
}
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
authQuery
(
SAuthCxt
*
pCxt
,
SNode
*
pStmt
)
{
switch
(
nodeType
(
pStmt
))
{
case
QUERY_NODE_SET_OPERATOR
:
return
authSetOperator
(
pCxt
,
(
SSetOperator
*
)
pStmt
);
case
QUERY_NODE_SELECT_STMT
:
return
authSelect
(
pCxt
,
(
SSelectStmt
*
)
pStmt
);
case
QUERY_NODE_VNODE_MODIF_STMT
:
case
QUERY_NODE_CREATE_DATABASE_STMT
:
case
QUERY_NODE_DROP_DATABASE_STMT
:
case
QUERY_NODE_ALTER_DATABASE_STMT
:
...
...
@@ -84,7 +90,10 @@ static int32_t authQuery(SAuthCxt* pCxt, SNode* pStmt) {
case
QUERY_NODE_ALTER_TABLE_STMT
:
case
QUERY_NODE_CREATE_USER_STMT
:
case
QUERY_NODE_ALTER_USER_STMT
:
case
QUERY_NODE_DROP_USER_STMT
:
break
;
case
QUERY_NODE_DROP_USER_STMT
:
{
return
authDropUser
(
pCxt
,
(
SDropUserReq
*
)
pStmt
);
}
case
QUERY_NODE_USE_DATABASE_STMT
:
case
QUERY_NODE_CREATE_DNODE_STMT
:
case
QUERY_NODE_DROP_DNODE_STMT
:
...
...
source/libs/parser/src/parCalcConst.c
浏览文件 @
4d07077b
...
...
@@ -262,9 +262,9 @@ static int32_t calcConstQuery(SCalcConstContext* pCxt, SNode* pStmt, bool subque
break
;
case
QUERY_NODE_SET_OPERATOR
:
{
SSetOperator
*
pSetOp
=
(
SSetOperator
*
)
pStmt
;
code
=
calcConstQuery
(
pCxt
,
pSetOp
->
pLeft
,
subquery
);
code
=
calcConstQuery
(
pCxt
,
pSetOp
->
pLeft
,
false
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
calcConstQuery
(
pCxt
,
pSetOp
->
pRight
,
subquery
);
code
=
calcConstQuery
(
pCxt
,
pSetOp
->
pRight
,
false
);
}
break
;
}
...
...
source/libs/parser/src/parTranslater.c
浏览文件 @
4d07077b
...
...
@@ -480,6 +480,31 @@ static EDealRes translateColumn(STranslateContext* pCxt, SColumnNode* pCol) {
return
res
;
}
static
int32_t
parseTimeFromValueNode
(
SValueNode
*
pVal
)
{
if
(
IS_SIGNED_NUMERIC_TYPE
(
pVal
->
node
.
resType
.
type
))
{
return
TSDB_CODE_SUCCESS
;
}
else
if
(
IS_UNSIGNED_NUMERIC_TYPE
(
pVal
->
node
.
resType
.
type
))
{
pVal
->
datum
.
i
=
pVal
->
datum
.
u
;
return
TSDB_CODE_SUCCESS
;
}
else
if
(
IS_FLOAT_TYPE
(
pVal
->
node
.
resType
.
type
))
{
pVal
->
datum
.
i
=
pVal
->
datum
.
d
;
return
TSDB_CODE_SUCCESS
;
}
else
if
(
TSDB_DATA_TYPE_BOOL
==
pVal
->
node
.
resType
.
type
)
{
pVal
->
datum
.
i
=
pVal
->
datum
.
b
;
return
TSDB_CODE_SUCCESS
;
}
else
if
(
IS_VAR_DATA_TYPE
(
pVal
->
node
.
resType
.
type
)
||
TSDB_DATA_TYPE_TIMESTAMP
==
pVal
->
node
.
resType
.
type
)
{
if
(
TSDB_CODE_SUCCESS
==
taosParseTime
(
pVal
->
literal
,
&
pVal
->
datum
.
i
,
pVal
->
node
.
resType
.
bytes
,
pVal
->
node
.
resType
.
precision
,
tsDaylight
))
{
return
TSDB_CODE_SUCCESS
;
}
char
*
pEnd
=
NULL
;
pVal
->
datum
.
i
=
strtoll
(
pVal
->
literal
,
&
pEnd
,
10
);
return
(
NULL
!=
pEnd
&&
'\0'
==
*
pEnd
)
?
TSDB_CODE_SUCCESS
:
TSDB_CODE_FAILED
;
}
else
{
return
TSDB_CODE_FAILED
;
}
}
static
EDealRes
translateValueImpl
(
STranslateContext
*
pCxt
,
SValueNode
*
pVal
,
SDataType
targetDt
)
{
uint8_t
precision
=
(
NULL
!=
pCxt
->
pCurrStmt
?
pCxt
->
pCurrStmt
->
precision
:
targetDt
.
precision
);
pVal
->
node
.
resType
.
precision
=
precision
;
...
...
@@ -571,7 +596,7 @@ static EDealRes translateValueImpl(STranslateContext* pCxt, SValueNode* pVal, SD
break
;
}
case
TSDB_DATA_TYPE_TIMESTAMP
:
{
if
(
taosParseTime
(
pVal
->
literal
,
&
pVal
->
datum
.
i
,
targetDt
.
bytes
,
precision
,
tsDaylight
)
!=
TSDB_CODE_SUCCESS
)
{
if
(
TSDB_CODE_SUCCESS
!=
parseTimeFromValueNode
(
pVal
)
)
{
return
generateDealNodeErrMsg
(
pCxt
,
TSDB_CODE_PAR_WRONG_VALUE_TYPE
,
pVal
->
literal
);
}
*
(
int64_t
*
)
&
pVal
->
typeData
=
pVal
->
datum
.
i
;
...
...
@@ -1660,10 +1685,10 @@ static int32_t createPrimaryKeyColByTable(STranslateContext* pCxt, STableNode* p
if
(
NULL
==
pCol
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
}
if
(
QUERY_NODE_REAL_TABLE
==
nodeType
(
pTable
))
{
setColumnInfoBySchema
((
SRealTableNode
*
)
pTable
,
((
SRealTableNode
*
)
pTable
)
->
pMeta
->
schema
,
false
,
pCol
);
}
else
{
// todo
pCol
->
colId
=
PRIMARYKEY_TIMESTAMP_COL_ID
;
strcpy
(
pCol
->
colName
,
PK_TS_COL_INTERNAL_NAME
);
if
(
!
findAndSetColumn
(
pCol
,
pTable
))
{
return
generateSyntaxErrMsg
(
&
pCxt
->
msgBuf
,
TSDB_CODE_PAR_INVALID_TIMELINE_FUNC
);
}
*
pPrimaryKey
=
(
SNode
*
)
pCol
;
return
TSDB_CODE_SUCCESS
;
...
...
source/libs/parser/src/parUtil.c
浏览文件 @
4d07077b
...
...
@@ -148,6 +148,10 @@ static char* getSyntaxErrFormat(int32_t errCode) {
return
"Invalid number of tag columns"
;
case
TSDB_CODE_PAR_INVALID_INTERNAL_PK
:
return
"Invalid _c0 or _rowts expression"
;
case
TSDB_CODE_PAR_INVALID_TIMELINE_FUNC
:
return
"Invalid timeline function"
;
case
TSDB_CODE_PAR_INVALID_PASSWD
:
return
"Invalid password"
;
case
TSDB_CODE_OUT_OF_MEMORY
:
return
"Out of memory"
;
default:
...
...
source/libs/parser/test/parSelectTest.cpp
浏览文件 @
4d07077b
...
...
@@ -187,7 +187,7 @@ TEST_F(ParserSelectTest, semanticError) {
run
(
"SELECT c2 FROM t1 tt1, t1 tt2 WHERE tt1.c1 = tt2.c1"
,
TSDB_CODE_PAR_AMBIGUOUS_COLUMN
,
PARSER_STAGE_TRANSLATE
);
// TSDB_CODE_PAR_WRONG_VALUE_TYPE
run
(
"SELECT timestamp '2010' FROM t1"
,
TSDB_CODE_PAR_WRONG_VALUE_TYPE
,
PARSER_STAGE_TRANSLATE
);
run
(
"SELECT timestamp '2010
a
' FROM t1"
,
TSDB_CODE_PAR_WRONG_VALUE_TYPE
,
PARSER_STAGE_TRANSLATE
);
// TSDB_CODE_PAR_ILLEGAL_USE_AGG_FUNCTION
run
(
"SELECT c2 FROM t1 tt1 join t1 tt2 on COUNT(*) > 0"
,
TSDB_CODE_PAR_ILLEGAL_USE_AGG_FUNCTION
,
...
...
@@ -235,9 +235,11 @@ TEST_F(ParserSelectTest, semanticError) {
TEST_F
(
ParserSelectTest
,
setOperator
)
{
useDb
(
"root"
,
"test"
);
run
(
"SELECT * FROM t1 UNION ALL SELECT * FROM t1"
);
//
run("SELECT * FROM t1 UNION ALL SELECT * FROM t1");
run
(
"(SELECT * FROM t1) UNION ALL (SELECT * FROM t1)"
);
// run("(SELECT * FROM t1) UNION ALL (SELECT * FROM t1)");
run
(
"SELECT c1 FROM (SELECT c1 FROM t1 UNION ALL SELECT c1 FROM t1)"
);
}
}
// namespace ParserTest
source/libs/planner/src/planOptimizer.c
浏览文件 @
4d07077b
...
...
@@ -582,7 +582,7 @@ static bool cpdIsPrimaryKeyEqualCond(SJoinLogicNode* pJoin, SNode* pCond) {
return
false
;
}
SOperatorNode
*
pOper
=
(
SOperatorNode
*
)
p
Join
->
pOnConditions
;
SOperatorNode
*
pOper
=
(
SOperatorNode
*
)
p
Cond
;
if
(
OP_TYPE_EQUAL
!=
pOper
->
opType
)
{
return
false
;
}
...
...
@@ -608,12 +608,16 @@ static int32_t cpdCheckLogicCond(SOptimizeContext* pCxt, SJoinLogicNode* pJoin,
if
(
LOGIC_COND_TYPE_AND
!=
pOnCond
->
condType
)
{
return
generateUsageErrMsg
(
pCxt
->
pPlanCxt
->
pMsg
,
pCxt
->
pPlanCxt
->
msgLen
,
TSDB_CODE_PLAN_EXPECTED_TS_EQUAL
);
}
bool
hasPrimaryKeyEqualCond
=
false
;
SNode
*
pCond
=
NULL
;
FOREACH
(
pCond
,
pOnCond
->
pParameterList
)
{
if
(
!
cpdIsPrimaryKeyEqualCond
(
pJoin
,
pCond
))
{
return
generateUsageErrMsg
(
pCxt
->
pPlanCxt
->
pMsg
,
pCxt
->
pPlanCxt
->
msgLen
,
TSDB_CODE_PLAN_EXPECTED_TS_EQUAL
)
;
if
(
cpdIsPrimaryKeyEqualCond
(
pJoin
,
pCond
))
{
hasPrimaryKeyEqualCond
=
true
;
}
}
if
(
!
hasPrimaryKeyEqualCond
)
{
return
generateUsageErrMsg
(
pCxt
->
pPlanCxt
->
pMsg
,
pCxt
->
pPlanCxt
->
msgLen
,
TSDB_CODE_PLAN_EXPECTED_TS_EQUAL
);
}
return
TSDB_CODE_SUCCESS
;
}
...
...
source/libs/planner/src/planPhysiCreater.c
浏览文件 @
4d07077b
...
...
@@ -261,6 +261,22 @@ typedef struct SSetSlotIdCxt {
SHashObj
*
pRightHash
;
}
SSetSlotIdCxt
;
static
void
dumpSlots
(
const
char
*
pName
,
SHashObj
*
pHash
)
{
if
(
NULL
==
pHash
)
{
return
;
}
planDebug
(
"%s"
,
pName
);
void
*
pIt
=
taosHashIterate
(
pHash
,
NULL
);
while
(
NULL
!=
pIt
)
{
size_t
len
=
0
;
char
*
pKey
=
taosHashGetKey
(
pIt
,
&
len
);
char
name
[
TSDB_TABLE_NAME_LEN
+
TSDB_COL_NAME_LEN
]
=
{
0
};
strncpy
(
name
,
pKey
,
len
);
planDebug
(
"
\t
slot name = %s"
,
name
);
pIt
=
taosHashIterate
(
pHash
,
pIt
);
}
}
static
EDealRes
doSetSlotId
(
SNode
*
pNode
,
void
*
pContext
)
{
if
(
QUERY_NODE_COLUMN
==
nodeType
(
pNode
)
&&
0
!=
strcmp
(((
SColumnNode
*
)
pNode
)
->
colName
,
"*"
))
{
SSetSlotIdCxt
*
pCxt
=
(
SSetSlotIdCxt
*
)
pContext
;
...
...
@@ -273,6 +289,8 @@ static EDealRes doSetSlotId(SNode* pNode, void* pContext) {
// pIndex is definitely not NULL, otherwise it is a bug
if
(
NULL
==
pIndex
)
{
planError
(
"doSetSlotId failed, invalid slot name %s"
,
name
);
dumpSlots
(
"left datablock desc"
,
pCxt
->
pLeftHash
);
dumpSlots
(
"right datablock desc"
,
pCxt
->
pRightHash
);
pCxt
->
errCode
=
TSDB_CODE_PLAN_INTERNAL_ERROR
;
return
DEAL_RES_ERROR
;
}
...
...
source/libs/planner/test/planJoinTest.cpp
浏览文件 @
4d07077b
...
...
@@ -23,10 +23,16 @@ class PlanJoinTest : public PlannerTestBase {};
TEST_F
(
PlanJoinTest
,
basic
)
{
useDb
(
"root"
,
"test"
);
run
(
"
select t1.c1, t2.c2 from st1s1 t1, st1s2 t2 where
t1.ts = t2.ts"
);
run
(
"
SELECT t1.c1, t2.c2 FROM st1s1 t1, st1s2 t2 WHERE
t1.ts = t2.ts"
);
run
(
"
select t1.*, t2.* from st1s1 t1, st1s2 t2 where
t1.ts = t2.ts"
);
run
(
"
SELECT t1.*, t2.* FROM st1s1 t1, st1s2 t2 WHERE
t1.ts = t2.ts"
);
// run("select t1.c1, t2.c1 from st1s1 t1 join st1s2 t2 on t1.ts = t2.ts where t1.c1 > t2.c1 and t1.c2 = 'abc' and "
// "t2.c2 = 'qwe'");
run
(
"SELECT t1.c1, t2.c1 FROM st1s1 t1 JOIN st1s2 t2 ON t1.ts = t2.ts"
);
}
TEST_F
(
PlanJoinTest
,
withWhere
)
{
useDb
(
"root"
,
"test"
);
run
(
"SELECT t1.c1, t2.c1 FROM st1s1 t1 JOIN st1s2 t2 ON t1.ts = t2.ts "
"WHERE t1.c1 > t2.c1 AND t1.c2 = 'abc' AND t2.c2 = 'qwe'"
);
}
source/libs/planner/test/planSubqueryTest.cpp
浏览文件 @
4d07077b
...
...
@@ -23,9 +23,13 @@ class PlanSubqeuryTest : public PlannerTestBase {};
TEST_F
(
PlanSubqeuryTest
,
basic
)
{
useDb
(
"root"
,
"test"
);
run
(
"SELECT * FROM (SELECT * FROM t1)"
);
if
(
0
==
g_skipSql
)
{
run
(
"SELECT * FROM (SELECT * FROM t1)"
);
// run("SELECT LAST(c1) FROM ( SELECT * FROM t1)");
run
(
"SELECT LAST(c1) FROM (SELECT * FROM t1)"
);
}
run
(
"SELECT c1 FROM (SELECT c1 FROM t1 UNION ALL SELECT c1 FROM t1)"
);
}
TEST_F
(
PlanSubqeuryTest
,
doubleGroupBy
)
{
...
...
source/libs/planner/test/planTestMain.cpp
浏览文件 @
4d07077b
...
...
@@ -25,23 +25,53 @@ class PlannerEnv : public testing::Environment {
virtual
void
SetUp
()
{
initMetaDataEnv
();
generateMetaData
();
initLog
(
"/tmp/td"
);
}
virtual
void
TearDown
()
{
destroyMetaDataEnv
();
}
PlannerEnv
()
{}
virtual
~
PlannerEnv
()
{}
private:
void
initLog
(
const
char
*
path
)
{
dDebugFlag
=
143
;
vDebugFlag
=
0
;
mDebugFlag
=
143
;
cDebugFlag
=
0
;
jniDebugFlag
=
0
;
tmrDebugFlag
=
135
;
uDebugFlag
=
135
;
rpcDebugFlag
=
143
;
qDebugFlag
=
143
;
wDebugFlag
=
0
;
sDebugFlag
=
0
;
tsdbDebugFlag
=
0
;
tsLogEmbedded
=
1
;
tsAsyncLog
=
0
;
taosRemoveDir
(
path
);
taosMkDir
(
path
);
tstrncpy
(
tsLogDir
,
path
,
PATH_MAX
);
if
(
taosInitLog
(
"taoslog"
,
1
)
!=
0
)
{
std
::
cout
<<
"failed to init log file"
<<
std
::
endl
;
}
}
};
static
void
parseArg
(
int
argc
,
char
*
argv
[])
{
int
opt
=
0
;
const
char
*
optstring
=
""
;
static
struct
option
long_options
[]
=
{{
"dump"
,
optional_argument
,
NULL
,
'd'
},
{
0
,
0
,
0
,
0
}};
static
struct
option
long_options
[]
=
{
{
"dump"
,
optional_argument
,
NULL
,
'd'
},
{
"skipSql"
,
optional_argument
,
NULL
,
's'
},
{
0
,
0
,
0
,
0
}};
while
((
opt
=
getopt_long
(
argc
,
argv
,
optstring
,
long_options
,
NULL
))
!=
-
1
)
{
switch
(
opt
)
{
case
'd'
:
setDumpModule
(
optarg
);
break
;
case
's'
:
g_skipSql
=
1
;
break
;
default:
break
;
}
...
...
source/libs/planner/test/planTestUtil.cpp
浏览文件 @
4d07077b
...
...
@@ -47,6 +47,7 @@ enum DumpModule {
};
DumpModule
g_dumpModule
=
DUMP_MODULE_NOTHING
;
int32_t
g_skipSql
=
0
;
void
setDumpModule
(
const
char
*
pModule
)
{
if
(
NULL
==
pModule
)
{
...
...
source/libs/planner/test/planTestUtil.h
浏览文件 @
4d07077b
...
...
@@ -32,6 +32,8 @@ class PlannerTestBase : public testing::Test {
std
::
unique_ptr
<
PlannerTestBaseImpl
>
impl_
;
};
extern
int32_t
g_skipSql
;
extern
void
setDumpModule
(
const
char
*
pModule
);
#endif // PLAN_TEST_UTIL_H
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录