Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
60e8bc24
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看板
提交
60e8bc24
编写于
5月 14, 2022
作者:
X
Xiaoyu Wang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: some problems of parser and planner
上级
84018cdb
变更
17
隐藏空白更改
内联
并排
Showing
17 changed file
with
315 addition
and
83 deletion
+315
-83
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/libs/nodes/src/nodesCodeFuncs.c
source/libs/nodes/src/nodesCodeFuncs.c
+91
-7
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
+4
-2
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
浏览文件 @
60e8bc24
...
...
@@ -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
浏览文件 @
60e8bc24
...
...
@@ -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
浏览文件 @
60e8bc24
...
...
@@ -635,6 +635,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/libs/nodes/src/nodesCodeFuncs.c
浏览文件 @
60e8bc24
...
...
@@ -1142,9 +1142,13 @@ static int32_t jsonToPhysiTableScanNode(const SJson* pJson, void* pObj) {
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"
;
...
...
@@ -2347,6 +2351,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"
;
...
...
@@ -2659,6 +2687,59 @@ 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
=
tjsonGetNumberValue
(
pJson
,
jkSetOperatorOpType
,
pNode
->
opType
);
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"
;
...
...
@@ -2673,7 +2754,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
);
...
...
@@ -2815,6 +2896,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
:
...
...
@@ -2844,9 +2926,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
:
...
...
@@ -2914,7 +2996,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
)));
...
...
@@ -2935,6 +3016,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
:
...
...
@@ -2951,6 +3034,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
:
...
...
@@ -3003,7 +3088,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
)));
...
...
source/libs/parser/src/parAstCreater.c
浏览文件 @
60e8bc24
...
...
@@ -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
浏览文件 @
60e8bc24
...
...
@@ -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
浏览文件 @
60e8bc24
...
...
@@ -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
浏览文件 @
60e8bc24
...
...
@@ -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
))
{
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
;
...
...
@@ -1658,10 +1683,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
浏览文件 @
60e8bc24
...
...
@@ -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
浏览文件 @
60e8bc24
...
...
@@ -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
浏览文件 @
60e8bc24
...
...
@@ -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
浏览文件 @
60e8bc24
...
...
@@ -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
浏览文件 @
60e8bc24
...
...
@@ -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
浏览文件 @
60e8bc24
...
...
@@ -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
浏览文件 @
60e8bc24
...
...
@@ -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
浏览文件 @
60e8bc24
...
...
@@ -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
浏览文件 @
60e8bc24
...
...
@@ -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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录