Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
慢慢CG
TDengine
提交
c1b456be
T
TDengine
项目概览
慢慢CG
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
c1b456be
编写于
1月 18, 2021
作者:
H
Hongze Cheng
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'develop' into feature/TD-1925_new
上级
f1d5c3f3
03fa1238
变更
54
展开全部
隐藏空白更改
内联
并排
Showing
54 changed file
with
1046 addition
and
2135 deletion
+1046
-2135
documentation20/webdocs/markdowndocs/TAOS SQL-ch.md
documentation20/webdocs/markdowndocs/TAOS SQL-ch.md
+1
-0
documentation20/webdocs/markdowndocs/architecture-ch.md
documentation20/webdocs/markdowndocs/architecture-ch.md
+1
-1
documentation20/webdocs/markdowndocs/cluster-ch.md
documentation20/webdocs/markdowndocs/cluster-ch.md
+1
-1
documentation20/webdocs/markdowndocs/cluster.md
documentation20/webdocs/markdowndocs/cluster.md
+1
-1
packaging/cfg/taos.cfg
packaging/cfg/taos.cfg
+3
-0
src/client/inc/tscLog.h
src/client/inc/tscLog.h
+3
-3
src/client/inc/tscSubquery.h
src/client/inc/tscSubquery.h
+3
-3
src/client/inc/tscUtil.h
src/client/inc/tscUtil.h
+3
-3
src/client/inc/tschemautil.h
src/client/inc/tschemautil.h
+0
-24
src/client/inc/tsclient.h
src/client/inc/tsclient.h
+5
-5
src/client/src/taos.def
src/client/src/taos.def
+0
-1
src/client/src/tscAsync.c
src/client/src/tscAsync.c
+2
-110
src/client/src/tscLocal.c
src/client/src/tscLocal.c
+8
-8
src/client/src/tscLocalMerge.c
src/client/src/tscLocalMerge.c
+5
-6
src/client/src/tscParseInsert.c
src/client/src/tscParseInsert.c
+2
-11
src/client/src/tscPrepare.c
src/client/src/tscPrepare.c
+88
-88
src/client/src/tscSQLParser.c
src/client/src/tscSQLParser.c
+19
-13
src/client/src/tscSchemaUtil.c
src/client/src/tscSchemaUtil.c
+0
-62
src/client/src/tscServer.c
src/client/src/tscServer.c
+19
-16
src/client/src/tscSql.c
src/client/src/tscSql.c
+9
-6
src/client/src/tscUtil.c
src/client/src/tscUtil.c
+15
-9
src/client/tests/cliTest.cpp
src/client/tests/cliTest.cpp
+132
-4
src/common/inc/tdataformat.h
src/common/inc/tdataformat.h
+1
-1
src/common/inc/tglobal.h
src/common/inc/tglobal.h
+1
-1
src/common/inc/tname.h
src/common/inc/tname.h
+14
-0
src/common/src/tglobal.c
src/common/src/tglobal.c
+1
-1
src/common/src/tname.c
src/common/src/tname.c
+67
-1
src/common/src/ttypes.c
src/common/src/ttypes.c
+20
-16
src/common/src/tvariant.c
src/common/src/tvariant.c
+4
-4
src/dnode/src/dnodeShell.c
src/dnode/src/dnodeShell.c
+1
-1
src/inc/taos.h
src/inc/taos.h
+1
-1
src/inc/taosdef.h
src/inc/taosdef.h
+26
-113
src/inc/taosmsg.h
src/inc/taosmsg.h
+29
-28
src/inc/ttype.h
src/inc/ttype.h
+86
-0
src/mnode/src/mnodeCluster.c
src/mnode/src/mnodeCluster.c
+1
-1
src/mnode/src/mnodeTable.c
src/mnode/src/mnodeTable.c
+113
-128
src/mnode/src/mnodeUser.c
src/mnode/src/mnodeUser.c
+1
-1
src/query/inc/qFill.h
src/query/inc/qFill.h
+2
-2
src/query/src/qAggMain.c
src/query/src/qAggMain.c
+2
-2
src/query/src/qArithmeticOperator.c
src/query/src/qArithmeticOperator.c
+4
-1121
src/query/src/qExecutor.c
src/query/src/qExecutor.c
+7
-9
src/query/src/qFill.c
src/query/src/qFill.c
+255
-237
src/query/src/qHistogram.c
src/query/src/qHistogram.c
+2
-2
src/query/src/qParserImpl.c
src/query/src/qParserImpl.c
+5
-5
src/query/tests/percentileTest.cpp
src/query/tests/percentileTest.cpp
+1
-1
src/tsdb/src/tsdbCommit.c
src/tsdb/src/tsdbCommit.c
+7
-7
src/tsdb/src/tsdbMeta.c
src/tsdb/src/tsdbMeta.c
+2
-2
src/tsdb/src/tsdbReadImpl.c
src/tsdb/src/tsdbReadImpl.c
+1
-1
src/util/src/tcompare.c
src/util/src/tcompare.c
+1
-1
src/vnode/src/vnodeWrite.c
src/vnode/src/vnodeWrite.c
+3
-3
tests/examples/c/asyncdemo.c
tests/examples/c/asyncdemo.c
+0
-3
tests/examples/c/demo.c
tests/examples/c/demo.c
+4
-4
tests/script/general/parser/columnValue_unsign.sim
tests/script/general/parser/columnValue_unsign.sim
+3
-2
tests/script/general/parser/testSuite.sim
tests/script/general/parser/testSuite.sim
+61
-61
未找到文件。
documentation20/webdocs/markdowndocs/TAOS SQL-ch.md
浏览文件 @
c1b456be
...
...
@@ -121,6 +121,7 @@ TDengine缺省的时间戳是毫秒精度,但通过修改配置参数enableMic
**Tips**: 以上所有参数修改后都可以用show databases来确认是否修改成功。
-
**显示系统所有数据库**
```mysql
SHOW DATABASES;
```
...
...
documentation20/webdocs/markdowndocs/architecture-ch.md
浏览文件 @
c1b456be
...
...
@@ -372,7 +372,7 @@ select count(*) from d1001 interval(1h);
select count(*) from d1001 interval(1h) fill(prev);
```
针对d1001设备采集数据统计每小时记录数,如果某一个小时不存在数据,
这
返回之前一个小时的统计数据。TDengine提供前向插值(prev)、线性插值(linear)、NULL值填充(NULL)、特定值填充(value)。
针对d1001设备采集数据统计每小时记录数,如果某一个小时不存在数据,
则
返回之前一个小时的统计数据。TDengine提供前向插值(prev)、线性插值(linear)、NULL值填充(NULL)、特定值填充(value)。
### 多表聚合查询
TDengine对每个数据采集点单独建表,但在实际应用中经常需要对不同的采集点数据进行聚合。为高效的进行聚合操作,TDengine引入超级表(STable)的概念。超级表用来代表一特定类型的数据采集点,它是包含多张表的表集合,集合里每张表的模式(schema)完全一致,但每张表都带有自己的静态标签,标签可以多个,可以随时增加、删除和修改。 应用可通过指定标签的过滤条件,对一个STable下的全部或部分表进行聚合或统计操作,这样大大简化应用的开发。其具体流程如下图所示:
...
...
documentation20/webdocs/markdowndocs/cluster-ch.md
浏览文件 @
c1b456be
...
...
@@ -227,5 +227,5 @@ SHOW MNODES;
如果副本数为偶数,当一个vnode group里一半vnode不工作时,是无法从中选出master的。同理,一半mnode不工作时,是无法选出mnode的master的,因为存在“split brain”问题。为解决这个问题,TDengine引入了arbitrator的概念。Arbitrator模拟一个vnode或mnode在工作,但只简单的负责网络连接,不处理任何数据插入或访问。只要包含arbitrator在内,超过半数的vnode或mnode工作,那么该vnode group或mnode组就可以正常的提供数据插入或查询服务。比如对于副本数为2的情形,如果一个节点A离线,但另外一个节点B正常,而且能连接到arbitrator, 那么节点B就能正常工作。
TDengine提供一个执行程序tarbitrator, 找任何一台Linux服务器运行它即可。请点击
[
安装包下载
](
https://www.taosdata.com/cn/all-downloads/
)
,在TDengine Arbitrator Linux一节中,选择适合的版本下载并安装。该程序对系统资源几乎没有要求,只需要保证有网络连接即可。该应用的命令行参数
`-p`
可以指定其对外服务的端口号,缺省是6042。配置每个taosd实例时,可以在配置文件taos.cfg里将参数arbitrator设置为arbitrator的End Point。如果该参数配置了,当副本数为偶数
数
,系统将自动连接配置的arbitrator。如果副本数为奇数,即使配置了arbitrator, 系统也不会去建立连接。
TDengine提供一个执行程序tarbitrator, 找任何一台Linux服务器运行它即可。请点击
[
安装包下载
](
https://www.taosdata.com/cn/all-downloads/
)
,在TDengine Arbitrator Linux一节中,选择适合的版本下载并安装。该程序对系统资源几乎没有要求,只需要保证有网络连接即可。该应用的命令行参数
`-p`
可以指定其对外服务的端口号,缺省是6042。配置每个taosd实例时,可以在配置文件taos.cfg里将参数arbitrator设置为arbitrator的End Point。如果该参数配置了,当副本数为偶数
时
,系统将自动连接配置的arbitrator。如果副本数为奇数,即使配置了arbitrator, 系统也不会去建立连接。
documentation20/webdocs/markdowndocs/cluster.md
浏览文件 @
c1b456be
...
...
@@ -141,6 +141,6 @@ SHOW MNODES;
如果副本数为偶数,当一个vnode group里一半vnode不工作时,是无法从中选出master的。同理,一半mnode不工作时,是无法选出mnode的master的,因为存在“split brain”问题。为解决这个问题,TDengine引入了arbitrator的概念。Arbitrator模拟一个vnode或mnode在工作,但只简单的负责网络连接,不处理任何数据插入或访问。只要包含arbitrator在内,超过半数的vnode或mnode工作,那么该vnode group或mnode组就可以正常的提供数据插入或查询服务。比如对于副本数为2的情形,如果一个节点A离线,但另外一个节点B正常,而且能连接到arbitrator, 那么节点B就能正常工作。
TDengine安装包里带有一个执行程序tarbitrator, 找任何一台Linux服务器运行它即可。该程序对系统资源几乎没有要求,只需要保证有网络连接即可。该应用的命令行参数
`-p`
可以指定其对外服务的端口号,缺省是6030。配置每个taosd实例时,可以在配置文件taos.cfg里将参数arbitrator设置为Arbitrator的End Point。如果该参数配置了,当副本数为偶数
数
,系统将自动连接配置的Arbitrator。
TDengine安装包里带有一个执行程序tarbitrator, 找任何一台Linux服务器运行它即可。该程序对系统资源几乎没有要求,只需要保证有网络连接即可。该应用的命令行参数
`-p`
可以指定其对外服务的端口号,缺省是6030。配置每个taosd实例时,可以在配置文件taos.cfg里将参数arbitrator设置为Arbitrator的End Point。如果该参数配置了,当副本数为偶数
时
,系统将自动连接配置的Arbitrator。
在配置了Arbitrator的情况下,它也会显示在“show dnodes;”指令给出的节点列表中。
packaging/cfg/taos.cfg
浏览文件 @
c1b456be
...
...
@@ -36,6 +36,9 @@
# 0.0: only one core available.
# tsRatioOfQueryCores 1.0
# the last_row/first/last aggregator will not change the original column name in the result fields
# keepColumnName 0
# number of management nodes in the system
# numOfMnodes 3
...
...
src/client/inc/tscLog.h
浏览文件 @
c1b456be
...
...
@@ -13,8 +13,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef TDENGINE_TSC
_
LOG_H
#define TDENGINE_TSC
_
LOG_H
#ifndef TDENGINE_TSCLOG_H
#define TDENGINE_TSCLOG_H
#ifdef __cplusplus
extern
"C"
{
...
...
@@ -22,7 +22,7 @@ extern "C" {
#include "tlog.h"
extern
int32_t
cDebugFlag
;
extern
u
int32_t
cDebugFlag
;
extern
int8_t
tscEmbedded
;
#define tscFatal(...) do { if (cDebugFlag & DEBUG_FATAL) { taosPrintLog("TSC FATAL ", tscEmbedded ? 255 : cDebugFlag, __VA_ARGS__); }} while(0)
...
...
src/client/inc/tscSubquery.h
浏览文件 @
c1b456be
...
...
@@ -13,8 +13,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef TDENGINE_TSC
JOINPROCESS
_H
#define TDENGINE_TSC
JOINPROCESS
_H
#ifndef TDENGINE_TSC
SUBQUERY
_H
#define TDENGINE_TSC
SUBQUERY
_H
#ifdef __cplusplus
extern
"C"
{
...
...
@@ -52,4 +52,4 @@ void tscUnlockByThread(int64_t *lockedBy);
}
#endif
#endif // TDENGINE_TSC
JOINPROCESS
_H
#endif // TDENGINE_TSC
SUBQUERY
_H
src/client/inc/tscUtil.h
浏览文件 @
c1b456be
...
...
@@ -110,7 +110,7 @@ void* tscDestroyBlockArrayList(SArray* pDataBlockList);
void
*
tscDestroyBlockHashTable
(
SHashObj
*
pBlockHashTable
);
int32_t
tscCopyDataBlockToPayload
(
SSqlObj
*
pSql
,
STableDataBlocks
*
pDataBlock
);
int32_t
tscMergeTableDataBlocks
(
SSqlObj
*
pSql
);
int32_t
tscMergeTableDataBlocks
(
SSqlObj
*
pSql
,
bool
freeBlockMap
);
int32_t
tscGetDataBlockFromList
(
SHashObj
*
pHashList
,
int64_t
id
,
int32_t
size
,
int32_t
startOffset
,
int32_t
rowSize
,
const
char
*
tableId
,
STableMeta
*
pTableMeta
,
STableDataBlocks
**
dataBlocks
,
SArray
*
pBlockList
);
...
...
@@ -256,11 +256,11 @@ void tscSVgroupInfoCopy(SVgroupInfo* dst, const SVgroupInfo* src);
* @param pPrevSql
* @return
*/
SSqlObj
*
createSimpleSubObj
(
SSqlObj
*
pSql
,
void
(
*
fp
)()
,
void
*
param
,
int32_t
cmd
);
SSqlObj
*
createSimpleSubObj
(
SSqlObj
*
pSql
,
__async_cb_func_t
fp
,
void
*
param
,
int32_t
cmd
);
void
registerSqlObj
(
SSqlObj
*
pSql
);
SSqlObj
*
createSubqueryObj
(
SSqlObj
*
pSql
,
int16_t
tableIndex
,
void
(
*
fp
)()
,
void
*
param
,
int32_t
cmd
,
SSqlObj
*
pPrevSql
);
SSqlObj
*
createSubqueryObj
(
SSqlObj
*
pSql
,
int16_t
tableIndex
,
__async_cb_func_t
fp
,
void
*
param
,
int32_t
cmd
,
SSqlObj
*
pPrevSql
);
void
addGroupInfoForSubquery
(
SSqlObj
*
pParentObj
,
SSqlObj
*
pSql
,
int32_t
subClauseIndex
,
int32_t
tableIndex
);
void
doAddGroupColumnForSubquery
(
SQueryInfo
*
pQueryInfo
,
int32_t
tagIndex
);
...
...
src/client/inc/tschemautil.h
浏览文件 @
c1b456be
...
...
@@ -24,10 +24,6 @@ extern "C" {
#include "tstoken.h"
#include "tsclient.h"
#define VALIDNUMOFCOLS(x) ((x) >= TSDB_MIN_COLUMNS && (x) <= TSDB_MAX_COLUMNS)
#define VALIDNUMOFTAGS(x) ((x) >= 0 && (x) <= TSDB_MAX_TAGS)
/**
* get the number of tags of this table
* @param pTableMeta
...
...
@@ -79,26 +75,6 @@ SSchema *tscGetTableColumnSchema(const STableMeta *pMeta, int32_t colIndex);
*/
SSchema
*
tscGetColumnSchemaById
(
STableMeta
*
pTableMeta
,
int16_t
colId
);
/**
* check if the schema is valid or not, including following aspects:
* 1. number of columns
* 2. column types
* 3. column length
* 4. column names
* 5. total length
*
* @param pSchema
* @param numOfCols
* @return
*/
bool
isValidSchema
(
struct
SSchema
*
pSchema
,
int32_t
numOfCols
,
int32_t
numOfTags
);
/**
* get the schema for the "tbname" column. it is a built column
* @return
*/
SSchema
tscGetTbnameColumnSchema
();
/**
* create the table meta from the msg
* @param pTableMetaMsg
...
...
src/client/inc/tsclient.h
浏览文件 @
c1b456be
...
...
@@ -235,7 +235,7 @@ typedef struct {
int32_t
numOfTablesInSubmit
;
};
uint32_t
insertType
;
uint32_t
insertType
;
// TODO remove it
int32_t
clauseIndex
;
// index of multiple subclause query
char
*
curSql
;
// current sql, resume position of sql after parsing paused
...
...
@@ -327,8 +327,8 @@ typedef struct SSqlObj {
pthread_t
owner
;
// owner of sql object, by which it is executed
STscObj
*
pTscObj
;
int64_t
rpcRid
;
void
(
*
fp
)()
;
void
(
*
fetchFp
)()
;
__async_cb_func_t
fp
;
__async_cb_func_t
fetchFp
;
void
*
param
;
int64_t
stime
;
uint32_t
queryId
;
...
...
@@ -463,7 +463,7 @@ static FORCE_INLINE void tscGetResultColumnChr(SSqlRes* pRes, SFieldInfo* pField
pRes
->
length
[
columnIndex
]
=
pInfo
->
pSqlExpr
->
param
[
1
].
nLen
;
pRes
->
tsrow
[
columnIndex
]
=
(
pInfo
->
pSqlExpr
->
param
[
1
].
nType
==
TSDB_DATA_TYPE_NULL
)
?
NULL
:
(
unsigned
char
*
)
pData
;
}
else
{
assert
(
bytes
==
tDataType
Desc
[
type
].
nSize
);
assert
(
bytes
==
tDataType
s
[
type
].
bytes
);
pRes
->
tsrow
[
columnIndex
]
=
isNull
(
pData
,
type
)
?
NULL
:
(
unsigned
char
*
)
&
pInfo
->
pSqlExpr
->
param
[
1
].
i64
;
pRes
->
length
[
columnIndex
]
=
bytes
;
...
...
@@ -480,7 +480,7 @@ static FORCE_INLINE void tscGetResultColumnChr(SSqlRes* pRes, SFieldInfo* pField
pRes
->
length
[
columnIndex
]
=
realLen
;
}
else
{
assert
(
bytes
==
tDataType
Desc
[
type
].
nSize
);
assert
(
bytes
==
tDataType
s
[
type
].
bytes
);
pRes
->
tsrow
[
columnIndex
]
=
isNull
(
pData
,
type
)
?
NULL
:
(
unsigned
char
*
)
pData
;
pRes
->
length
[
columnIndex
]
=
bytes
;
...
...
src/client/src/taos.def
浏览文件 @
c1b456be
...
...
@@ -32,7 +32,6 @@ taos_errstr
taos_errno
taos_query_a
taos_fetch_rows_a
taos_fetch_row_a
taos_subscribe
taos_consume
taos_unsubscribe
...
...
src/client/src/tscAsync.c
浏览文件 @
c1b456be
...
...
@@ -20,24 +20,19 @@
#include "trpc.h"
#include "tscLog.h"
#include "tscSubquery.h"
#include "tscLocalMerge.h"
#include "tscUtil.h"
#include "tsched.h"
#include "tschemautil.h"
#include "tsclient.h"
static
void
tscProcessFetchRow
(
SSchedMsg
*
pMsg
);
static
void
tscAsyncQueryRowsForNextVnode
(
void
*
param
,
TAOS_RES
*
tres
,
int
numOfRows
);
static
void
tscProcessAsyncRetrieveImpl
(
void
*
param
,
TAOS_RES
*
tres
,
int
numOfRows
,
void
(
*
fp
)());
/*
* Proxy function to perform sequentially query&retrieve operation.
* If sql queries upon a super table and two-stage merge procedure is not involved (when employ the projection
* query), it will sequentially query&retrieve data for all vnodes
*/
static
void
tscAsyncFetchRowsProxy
(
void
*
param
,
TAOS_RES
*
tres
,
int
numOfRows
);
static
void
tscAsyncFetchSingleRowProxy
(
void
*
param
,
TAOS_RES
*
tres
,
int
numOfRows
);
void
doAsyncQuery
(
STscObj
*
pObj
,
SSqlObj
*
pSql
,
__async_cb_func_t
fp
,
void
*
param
,
const
char
*
sqlstr
,
size_t
sqlLen
)
{
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
...
...
@@ -148,7 +143,7 @@ static void tscAsyncFetchRowsProxy(void *param, TAOS_RES *tres, int numOfRows) {
}
// actual continue retrieve function with user-specified callback function
static
void
tscProcessAsyncRetrieveImpl
(
void
*
param
,
TAOS_RES
*
tres
,
int
numOfRows
,
void
(
*
fp
)()
)
{
static
void
tscProcessAsyncRetrieveImpl
(
void
*
param
,
TAOS_RES
*
tres
,
int
numOfRows
,
__async_cb_func_t
fp
)
{
SSqlObj
*
pSql
=
(
SSqlObj
*
)
tres
;
if
(
pSql
==
NULL
)
{
// error
tscError
(
"sql object is NULL"
);
...
...
@@ -191,11 +186,6 @@ static void tscAsyncQueryRowsForNextVnode(void *param, TAOS_RES *tres, int numOf
tscProcessAsyncRetrieveImpl
(
param
,
tres
,
numOfRows
,
tscAsyncFetchRowsProxy
);
}
void
tscAsyncQuerySingleRowForNextVnode
(
void
*
param
,
TAOS_RES
*
tres
,
int
numOfRows
)
{
// query completed, continue to retrieve
tscProcessAsyncRetrieveImpl
(
param
,
tres
,
numOfRows
,
tscAsyncFetchSingleRowProxy
);
}
void
taos_fetch_rows_a
(
TAOS_RES
*
taosa
,
__async_cb_func_t
fp
,
void
*
param
)
{
SSqlObj
*
pSql
=
(
SSqlObj
*
)
taosa
;
if
(
pSql
==
NULL
||
pSql
->
signature
!=
pSql
)
{
...
...
@@ -263,103 +253,6 @@ void taos_fetch_rows_a(TAOS_RES *taosa, __async_cb_func_t fp, void *param) {
}
}
void
taos_fetch_row_a
(
TAOS_RES
*
taosa
,
void
(
*
fp
)(
void
*
,
TAOS_RES
*
,
TAOS_ROW
),
void
*
param
)
{
SSqlObj
*
pSql
=
(
SSqlObj
*
)
taosa
;
if
(
pSql
==
NULL
||
pSql
->
signature
!=
pSql
)
{
tscError
(
"sql object is NULL"
);
tscQueueAsyncError
(
fp
,
param
,
TSDB_CODE_TSC_DISCONNECTED
);
return
;
}
SSqlRes
*
pRes
=
&
pSql
->
res
;
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
if
(
pRes
->
qhandle
==
0
)
{
tscError
(
"qhandle is NULL"
);
pSql
->
param
=
param
;
pRes
->
code
=
TSDB_CODE_TSC_INVALID_QHANDLE
;
tscAsyncResultOnError
(
pSql
);
return
;
}
pSql
->
fetchFp
=
fp
;
pSql
->
param
=
param
;
if
(
pRes
->
row
>=
pRes
->
numOfRows
)
{
tscResetForNextRetrieve
(
pRes
);
pSql
->
fp
=
tscAsyncFetchSingleRowProxy
;
if
(
pCmd
->
command
!=
TSDB_SQL_RETRIEVE_LOCALMERGE
&&
pCmd
->
command
<
TSDB_SQL_LOCAL
)
{
pCmd
->
command
=
(
pCmd
->
command
>
TSDB_SQL_MGMT
)
?
TSDB_SQL_RETRIEVE
:
TSDB_SQL_FETCH
;
}
tscProcessSql
(
pSql
);
}
else
{
SSchedMsg
schedMsg
=
{
0
};
schedMsg
.
fp
=
tscProcessFetchRow
;
schedMsg
.
ahandle
=
pSql
;
schedMsg
.
thandle
=
pRes
->
tsrow
;
schedMsg
.
msg
=
NULL
;
taosScheduleTask
(
tscQhandle
,
&
schedMsg
);
}
}
void
tscAsyncFetchSingleRowProxy
(
void
*
param
,
TAOS_RES
*
tres
,
int
numOfRows
)
{
SSqlObj
*
pSql
=
(
SSqlObj
*
)
tres
;
SSqlRes
*
pRes
=
&
pSql
->
res
;
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
pCmd
->
clauseIndex
);
if
(
numOfRows
==
0
)
{
if
(
hasMoreVnodesToTry
(
pSql
))
{
// sequentially retrieve data from remain vnodes.
tscTryQueryNextVnode
(
pSql
,
tscAsyncQuerySingleRowForNextVnode
);
}
else
{
/*
* 1. has reach the limitation
* 2. no remain virtual nodes to be retrieved anymore
*/
(
*
pSql
->
fetchFp
)(
pSql
->
param
,
pSql
,
NULL
);
}
return
;
}
for
(
int
i
=
0
;
i
<
pCmd
->
numOfCols
;
++
i
){
SInternalField
*
pSup
=
taosArrayGet
(
pQueryInfo
->
fieldsInfo
.
internalField
,
i
);
if
(
pSup
->
pSqlExpr
!=
NULL
)
{
// pRes->tsrow[i] = TSC_GET_RESPTR_BASE(pRes, pQueryInfo, i) + pSup->pSqlExpr->resBytes * pRes->row;
}
else
{
//todo add
}
}
pRes
->
row
++
;
(
*
pSql
->
fetchFp
)(
pSql
->
param
,
pSql
,
pSql
->
res
.
tsrow
);
}
void
tscProcessFetchRow
(
SSchedMsg
*
pMsg
)
{
SSqlObj
*
pSql
=
(
SSqlObj
*
)
pMsg
->
ahandle
;
SSqlRes
*
pRes
=
&
pSql
->
res
;
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
pCmd
->
clauseIndex
);
for
(
int
i
=
0
;
i
<
pCmd
->
numOfCols
;
++
i
)
{
SInternalField
*
pSup
=
taosArrayGet
(
pQueryInfo
->
fieldsInfo
.
internalField
,
i
);
if
(
pSup
->
pSqlExpr
!=
NULL
)
{
tscGetResultColumnChr
(
pRes
,
&
pQueryInfo
->
fieldsInfo
,
i
,
0
);
}
else
{
// todo add
}
}
pRes
->
row
++
;
(
*
pSql
->
fetchFp
)(
pSql
->
param
,
pSql
,
pRes
->
tsrow
);
}
// this function will be executed by queue task threads, so the terrno is not valid
static
void
tscProcessAsyncError
(
SSchedMsg
*
pMsg
)
{
void
(
*
fp
)()
=
pMsg
->
ahandle
;
...
...
@@ -372,7 +265,7 @@ void tscQueueAsyncError(void(*fp), void *param, int32_t code) {
int32_t
*
c
=
malloc
(
sizeof
(
int32_t
));
*
c
=
code
;
SSchedMsg
schedMsg
=
{
0
};
SSchedMsg
schedMsg
=
{
0
};
schedMsg
.
fp
=
tscProcessAsyncError
;
schedMsg
.
ahandle
=
fp
;
schedMsg
.
thandle
=
param
;
...
...
@@ -380,7 +273,6 @@ void tscQueueAsyncError(void(*fp), void *param, int32_t code) {
taosScheduleTask
(
tscQhandle
,
&
schedMsg
);
}
void
tscAsyncResultOnError
(
SSqlObj
*
pSql
)
{
if
(
pSql
==
NULL
||
pSql
->
signature
!=
pSql
)
{
tscDebug
(
"%p SqlObj is freed, not add into queue async res"
,
pSql
);
...
...
src/client/src/tscLocal.c
浏览文件 @
c1b456be
...
...
@@ -79,7 +79,7 @@ static int32_t tscSetValueToResObj(SSqlObj *pSql, int32_t rowLen) {
char
*
dst
=
pRes
->
data
+
tscFieldInfoGetOffset
(
pQueryInfo
,
0
)
*
totalNumOfRows
+
pField
->
bytes
*
i
;
STR_WITH_MAXSIZE_TO_VARSTR
(
dst
,
pSchema
[
i
].
name
,
pField
->
bytes
);
char
*
type
=
tDataType
Desc
[
pSchema
[
i
].
type
].
aN
ame
;
char
*
type
=
tDataType
s
[
pSchema
[
i
].
type
].
n
ame
;
pField
=
tscFieldInfoGetField
(
&
pQueryInfo
->
fieldsInfo
,
1
);
dst
=
pRes
->
data
+
tscFieldInfoGetOffset
(
pQueryInfo
,
1
)
*
totalNumOfRows
+
pField
->
bytes
*
i
;
...
...
@@ -119,7 +119,7 @@ static int32_t tscSetValueToResObj(SSqlObj *pSql, int32_t rowLen) {
// type name
pField
=
tscFieldInfoGetField
(
&
pQueryInfo
->
fieldsInfo
,
1
);
char
*
type
=
tDataType
Desc
[
pSchema
[
i
].
type
].
aN
ame
;
char
*
type
=
tDataType
s
[
pSchema
[
i
].
type
].
n
ame
;
output
=
pRes
->
data
+
tscFieldInfoGetOffset
(
pQueryInfo
,
1
)
*
totalNumOfRows
+
pField
->
bytes
*
i
;
STR_WITH_MAXSIZE_TO_VARSTR
(
output
,
type
,
pField
->
bytes
);
...
...
@@ -619,9 +619,9 @@ static int32_t tscRebuildDDLForNormalTable(SSqlObj *pSql, const char *tableName,
if
(
type
==
TSDB_DATA_TYPE_NCHAR
)
{
bytes
=
bytes
/
TSDB_NCHAR_SIZE
;
}
snprintf
(
result
+
strlen
(
result
),
TSDB_MAX_BINARY_LEN
-
strlen
(
result
),
"%s %s(%d),"
,
pSchema
[
i
].
name
,
tDataType
Desc
[
pSchema
[
i
].
type
].
aN
ame
,
bytes
);
snprintf
(
result
+
strlen
(
result
),
TSDB_MAX_BINARY_LEN
-
strlen
(
result
),
"%s %s(%d),"
,
pSchema
[
i
].
name
,
tDataType
s
[
pSchema
[
i
].
type
].
n
ame
,
bytes
);
}
else
{
snprintf
(
result
+
strlen
(
result
),
TSDB_MAX_BINARY_LEN
-
strlen
(
result
),
"%s %s,"
,
pSchema
[
i
].
name
,
tDataType
Desc
[
pSchema
[
i
].
type
].
aName
);
snprintf
(
result
+
strlen
(
result
),
TSDB_MAX_BINARY_LEN
-
strlen
(
result
),
"%s %s,"
,
pSchema
[
i
].
name
,
tDataType
s
[
pSchema
[
i
].
type
].
name
);
}
}
sprintf
(
result
+
strlen
(
result
)
-
1
,
"%s"
,
")"
);
...
...
@@ -646,9 +646,9 @@ static int32_t tscRebuildDDLForSuperTable(SSqlObj *pSql, const char *tableName,
if
(
type
==
TSDB_DATA_TYPE_NCHAR
)
{
bytes
=
bytes
/
TSDB_NCHAR_SIZE
;
}
snprintf
(
result
+
strlen
(
result
),
TSDB_MAX_BINARY_LEN
-
strlen
(
result
),
"%s %s(%d),"
,
pSchema
[
i
].
name
,
tDataType
Desc
[
pSchema
[
i
].
type
].
aN
ame
,
bytes
);
snprintf
(
result
+
strlen
(
result
),
TSDB_MAX_BINARY_LEN
-
strlen
(
result
),
"%s %s(%d),"
,
pSchema
[
i
].
name
,
tDataType
s
[
pSchema
[
i
].
type
].
n
ame
,
bytes
);
}
else
{
snprintf
(
result
+
strlen
(
result
),
TSDB_MAX_BINARY_LEN
-
strlen
(
result
),
"%s %s,"
,
pSchema
[
i
].
name
,
tDataType
Desc
[
type
].
aName
);
snprintf
(
result
+
strlen
(
result
),
TSDB_MAX_BINARY_LEN
-
strlen
(
result
),
"%s %s,"
,
pSchema
[
i
].
name
,
tDataType
s
[
type
].
name
);
}
}
snprintf
(
result
+
strlen
(
result
)
-
1
,
TSDB_MAX_BINARY_LEN
-
strlen
(
result
),
"%s %s"
,
")"
,
"TAGS ("
);
...
...
@@ -660,9 +660,9 @@ static int32_t tscRebuildDDLForSuperTable(SSqlObj *pSql, const char *tableName,
if
(
type
==
TSDB_DATA_TYPE_NCHAR
)
{
bytes
=
bytes
/
TSDB_NCHAR_SIZE
;
}
snprintf
(
result
+
strlen
(
result
),
TSDB_MAX_BINARY_LEN
-
strlen
(
result
),
"%s %s(%d),"
,
pSchema
[
i
].
name
,
tDataType
Desc
[
pSchema
[
i
].
type
].
aN
ame
,
bytes
);
snprintf
(
result
+
strlen
(
result
),
TSDB_MAX_BINARY_LEN
-
strlen
(
result
),
"%s %s(%d),"
,
pSchema
[
i
].
name
,
tDataType
s
[
pSchema
[
i
].
type
].
n
ame
,
bytes
);
}
else
{
snprintf
(
result
+
strlen
(
result
),
TSDB_MAX_BINARY_LEN
-
strlen
(
result
),
"%s %s,"
,
pSchema
[
i
].
name
,
tDataType
Desc
[
type
].
aName
);
snprintf
(
result
+
strlen
(
result
),
TSDB_MAX_BINARY_LEN
-
strlen
(
result
),
"%s %s,"
,
pSchema
[
i
].
name
,
tDataType
s
[
type
].
name
);
}
}
sprintf
(
result
+
strlen
(
result
)
-
1
,
"%s"
,
")"
);
...
...
src/client/src/tscLocalMerge.c
浏览文件 @
c1b456be
...
...
@@ -979,14 +979,13 @@ static void doFillResult(SSqlObj *pSql, SLocalReducer *pLocalReducer, bool doneO
pQueryInfo
->
limit
.
offset
-=
newRows
;
pRes
->
numOfRows
=
0
;
int32_t
rpoints
=
taosNumOfRemainRows
(
pFillInfo
);
if
(
rpoints
<=
0
)
{
if
(
!
taosFillHasMoreResults
(
pFillInfo
))
{
if
(
!
doneOutput
)
{
// reduce procedure has not completed yet, but current results for fill are exhausted
break
;
}
// all output in current group are completed
int32_t
totalRemainRows
=
(
int32_t
)
getNumOfRes
WithFill
(
pFillInfo
,
actualETime
,
pLocalReducer
->
resColModel
->
capacity
);
int32_t
totalRemainRows
=
(
int32_t
)
getNumOfRes
ultsAfterFillGap
(
pFillInfo
,
actualETime
,
pLocalReducer
->
resColModel
->
capacity
);
if
(
totalRemainRows
<=
0
)
{
break
;
}
...
...
@@ -1337,14 +1336,14 @@ static bool doBuildFilledResultForGroup(SSqlObj *pSql) {
SLocalReducer
*
pLocalReducer
=
pRes
->
pLocalReducer
;
SFillInfo
*
pFillInfo
=
pLocalReducer
->
pFillInfo
;
if
(
pFillInfo
!=
NULL
&&
taos
NumOfRemainRows
(
pFillInfo
)
>
0
)
{
if
(
pFillInfo
!=
NULL
&&
taos
FillHasMoreResults
(
pFillInfo
)
)
{
assert
(
pQueryInfo
->
fillType
!=
TSDB_FILL_NONE
);
tFilePage
*
pFinalDataBuf
=
pLocalReducer
->
pResultBuf
;
int64_t
etime
=
*
(
int64_t
*
)(
pFinalDataBuf
->
data
+
TSDB_KEYSIZE
*
(
pFillInfo
->
numOfRows
-
1
));
// the first column must be the timestamp column
int32_t
rows
=
(
int32_t
)
getNumOfRes
WithFill
(
pFillInfo
,
etime
,
pLocalReducer
->
resColModel
->
capacity
);
int32_t
rows
=
(
int32_t
)
getNumOfRes
ultsAfterFillGap
(
pFillInfo
,
etime
,
pLocalReducer
->
resColModel
->
capacity
);
if
(
rows
>
0
)
{
// do fill gap
doFillResult
(
pSql
,
pLocalReducer
,
false
);
}
...
...
@@ -1373,7 +1372,7 @@ static bool doHandleLastRemainData(SSqlObj *pSql) {
((
pRes
->
numOfRowsGroup
<
pQueryInfo
->
limit
.
limit
&&
pQueryInfo
->
limit
.
limit
>
0
)
||
(
pQueryInfo
->
limit
.
limit
<
0
)))
{
int64_t
etime
=
(
pQueryInfo
->
order
.
order
==
TSDB_ORDER_ASC
)
?
pQueryInfo
->
window
.
ekey
:
pQueryInfo
->
window
.
skey
;
int32_t
rows
=
(
int32_t
)
getNumOfRes
WithFill
(
pFillInfo
,
etime
,
pLocalReducer
->
resColModel
->
capacity
);
int32_t
rows
=
(
int32_t
)
getNumOfRes
ultsAfterFillGap
(
pFillInfo
,
etime
,
pLocalReducer
->
resColModel
->
capacity
);
if
(
rows
>
0
)
{
doFillResult
(
pSql
,
pLocalReducer
,
true
);
}
...
...
src/client/src/tscParseInsert.c
浏览文件 @
c1b456be
...
...
@@ -1281,7 +1281,7 @@ int tsParseInsertSql(SSqlObj *pSql) {
}
if
(
taosHashGetSize
(
pCmd
->
pTableBlockHashList
)
>
0
)
{
// merge according to vgId
if
((
code
=
tscMergeTableDataBlocks
(
pSql
))
!=
TSDB_CODE_SUCCESS
)
{
if
((
code
=
tscMergeTableDataBlocks
(
pSql
,
true
))
!=
TSDB_CODE_SUCCESS
)
{
goto
_clean
;
}
}
...
...
@@ -1336,15 +1336,6 @@ int tsParseSql(SSqlObj *pSql, bool initial) {
}
if
(
tscIsInsertData
(
pSql
->
sqlstr
))
{
/*
* Set the fp before parse the sql string, in case of getTableMeta failed, in which
* the error handle callback function can rightfully restore the user-defined callback function (fp).
*/
if
(
initial
&&
(
pSql
->
cmd
.
insertType
!=
TSDB_QUERY_TYPE_STMT_INSERT
))
{
pSql
->
fetchFp
=
pSql
->
fp
;
pSql
->
fp
=
(
void
(
*
)())
tscHandleMultivnodeInsert
;
}
if
(
initial
&&
((
ret
=
tsInsertInitialCheck
(
pSql
))
!=
TSDB_CODE_SUCCESS
))
{
return
ret
;
}
...
...
@@ -1398,7 +1389,7 @@ static int doPackSendDataBlock(SSqlObj *pSql, int32_t numOfRows, STableDataBlock
return
tscInvalidSQLErrMsg
(
pCmd
->
payload
,
"too many rows in sql, total number of rows should be less than 32767"
,
NULL
);
}
if
((
code
=
tscMergeTableDataBlocks
(
pSql
))
!=
TSDB_CODE_SUCCESS
)
{
if
((
code
=
tscMergeTableDataBlocks
(
pSql
,
true
))
!=
TSDB_CODE_SUCCESS
)
{
return
code
;
}
...
...
src/client/src/tscPrepare.c
浏览文件 @
c1b456be
...
...
@@ -255,7 +255,6 @@ static char* normalStmtBuildSql(STscStmt* stmt) {
////////////////////////////////////////////////////////////////////////////////
// functions for insertion statement preparation
static
int
doBindParam
(
char
*
data
,
SParamInfo
*
param
,
TAOS_BIND
*
bind
)
{
if
(
bind
->
is_null
!=
NULL
&&
*
(
bind
->
is_null
))
{
setNull
(
data
+
param
->
offset
,
param
->
type
,
param
->
bytes
);
...
...
@@ -697,61 +696,44 @@ static int doBindParam(char* data, SParamInfo* param, TAOS_BIND* bind) {
static
int
insertStmtBindParam
(
STscStmt
*
stmt
,
TAOS_BIND
*
bind
)
{
SSqlCmd
*
pCmd
=
&
stmt
->
pSql
->
cmd
;
int32_t
alloced
=
1
,
binded
=
0
;
if
(
pCmd
->
batchSize
>
0
)
{
alloced
=
(
pCmd
->
batchSize
+
1
)
/
2
;
binded
=
pCmd
->
batchSize
/
2
;
STableMetaInfo
*
pTableMetaInfo
=
tscGetTableMetaInfoFromCmd
(
pCmd
,
0
,
0
);
STableMeta
*
pTableMeta
=
pTableMetaInfo
->
pTableMeta
;
if
(
pCmd
->
pTableBlockHashList
==
NULL
)
{
pCmd
->
pTableBlockHashList
=
taosHashInit
(
16
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BIGINT
),
true
,
false
);
}
size_t
size
=
taosArrayGetSize
(
pCmd
->
pDataBlocks
);
for
(
int32_t
i
=
0
;
i
<
size
;
++
i
)
{
STableDataBlocks
*
pBlock
=
taosArrayGetP
(
pCmd
->
pDataBlocks
,
i
);
uint32_t
totalDataSize
=
pBlock
->
size
-
sizeof
(
SSubmitBlk
);
uint32_t
dataSize
=
totalDataSize
/
alloced
;
assert
(
dataSize
*
alloced
==
totalDataSize
);
if
(
alloced
==
binded
)
{
totalDataSize
+=
dataSize
+
sizeof
(
SSubmitBlk
);
if
(
totalDataSize
>
pBlock
->
nAllocSize
)
{
const
double
factor
=
1
.
5
;
void
*
tmp
=
realloc
(
pBlock
->
pData
,
(
uint32_t
)(
totalDataSize
*
factor
));
if
(
tmp
==
NULL
)
{
return
TSDB_CODE_TSC_OUT_OF_MEMORY
;
}
pBlock
->
pData
=
(
char
*
)
tmp
;
pBlock
->
nAllocSize
=
(
uint32_t
)(
totalDataSize
*
factor
);
}
}
STableDataBlocks
*
pBlock
=
NULL
;
char
*
data
=
pBlock
->
pData
+
sizeof
(
SSubmitBlk
)
+
dataSize
*
binded
;
for
(
uint32_t
j
=
0
;
j
<
pBlock
->
numOfParams
;
++
j
)
{
SParamInfo
*
param
=
pBlock
->
params
+
j
;
int
code
=
doBindParam
(
data
,
param
,
bind
+
param
->
idx
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
tscDebug
(
"param %d: type mismatch or invalid"
,
param
->
idx
);
return
code
;
}
}
int32_t
ret
=
tscGetDataBlockFromList
(
pCmd
->
pTableBlockHashList
,
pTableMeta
->
id
.
uid
,
TSDB_PAYLOAD_SIZE
,
sizeof
(
SSubmitBlk
),
pTableMeta
->
tableInfo
.
rowSize
,
pTableMetaInfo
->
name
,
pTableMeta
,
&
pBlock
,
NULL
);
if
(
ret
!=
0
)
{
// todo handle error
}
// actual work of all data blocks is done, update block size and numOfRows.
// note we don't do this block by block during the binding process, because
// we cannot recover if something goes wrong.
pCmd
->
batchSize
=
binded
*
2
+
1
;
uint32_t
totalDataSize
=
sizeof
(
SSubmitBlk
)
+
pCmd
->
batchSize
*
pBlock
->
rowSize
;
if
(
totalDataSize
>
pBlock
->
nAllocSize
)
{
const
double
factor
=
1
.
5
;
if
(
binded
<
alloced
)
{
return
TSDB_CODE_SUCCESS
;
}
void
*
tmp
=
realloc
(
pBlock
->
pData
,
(
uint32_t
)(
totalDataSize
*
factor
));
if
(
tmp
==
NULL
)
{
return
TSDB_CODE_TSC_OUT_OF_MEMORY
;
}
size_t
total
=
taosArrayGetSize
(
pCmd
->
pDataBlocks
)
;
for
(
int32_t
i
=
0
;
i
<
total
;
++
i
)
{
STableDataBlocks
*
pBlock
=
taosArrayGetP
(
pCmd
->
pDataBlocks
,
i
);
pBlock
->
pData
=
(
char
*
)
tmp
;
pBlock
->
nAllocSize
=
(
uint32_t
)(
totalDataSize
*
factor
);
}
uint32_t
totalDataSize
=
pBlock
->
size
-
sizeof
(
SSubmitBlk
);
pBlock
->
size
+=
totalDataSize
/
alloced
;
char
*
data
=
pBlock
->
pData
+
sizeof
(
SSubmitBlk
)
+
pBlock
->
rowSize
*
pCmd
->
batchSize
;
for
(
uint32_t
j
=
0
;
j
<
pBlock
->
numOfParams
;
++
j
)
{
SParamInfo
*
param
=
&
pBlock
->
params
[
j
];
SSubmitBlk
*
pSubmit
=
(
SSubmitBlk
*
)
pBlock
->
pData
;
pSubmit
->
numOfRows
+=
pSubmit
->
numOfRows
/
alloced
;
int
code
=
doBindParam
(
data
,
param
,
&
bind
[
param
->
idx
]);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
tscDebug
(
"param %d: type mismatch or invalid"
,
param
->
idx
);
return
code
;
}
}
return
TSDB_CODE_SUCCESS
;
...
...
@@ -759,9 +741,7 @@ static int insertStmtBindParam(STscStmt* stmt, TAOS_BIND* bind) {
static
int
insertStmtAddBatch
(
STscStmt
*
stmt
)
{
SSqlCmd
*
pCmd
=
&
stmt
->
pSql
->
cmd
;
if
((
pCmd
->
batchSize
%
2
)
==
1
)
{
++
pCmd
->
batchSize
;
}
++
pCmd
->
batchSize
;
return
TSDB_CODE_SUCCESS
;
}
...
...
@@ -793,50 +773,66 @@ static int insertStmtExecute(STscStmt* stmt) {
if
(
pCmd
->
batchSize
==
0
)
{
return
TSDB_CODE_TSC_INVALID_VALUE
;
}
if
((
pCmd
->
batchSize
%
2
)
==
1
)
{
++
pCmd
->
batchSize
;
}
STableMetaInfo
*
pTableMetaInfo
=
tscGetTableMetaInfoFromCmd
(
pCmd
,
pCmd
->
clauseIndex
,
0
);
assert
(
pCmd
->
numOfClause
==
1
);
if
(
taosHashGetSize
(
pCmd
->
pTableBlockHashList
)
==
0
)
{
return
TSDB_CODE_SUCCESS
;
}
if
(
taosHashGetSize
(
pCmd
->
pTableBlockHashList
)
>
0
)
{
// merge according to vgid
int
code
=
tscMergeTableDataBlocks
(
stmt
->
pSql
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
return
code
;
}
STableDataBlocks
*
pDataBlock
=
taosArrayGetP
(
pCmd
->
pDataBlocks
,
0
);
code
=
tscCopyDataBlockToPayload
(
stmt
->
pSql
,
pDataBlock
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
return
code
;
}
STableMetaInfo
*
pTableMetaInfo
=
tscGetTableMetaInfoFromCmd
(
pCmd
,
0
,
0
);
// set the next sent data vnode index in data block arraylist
pTableMetaInfo
->
vgroupIndex
=
1
;
}
else
{
pCmd
->
pDataBlocks
=
tscDestroyBlockArrayList
(
pCmd
->
pDataBlocks
);
STableMeta
*
pTableMeta
=
pTableMetaInfo
->
pTableMeta
;
if
(
pCmd
->
pTableBlockHashList
==
NULL
)
{
pCmd
->
pTableBlockHashList
=
taosHashInit
(
16
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BIGINT
),
true
,
false
);
}
SSqlObj
*
pSql
=
stmt
->
pSql
;
SSqlRes
*
pRes
=
&
pSql
->
res
;
pRes
->
numOfRows
=
0
;
pRes
->
numOfTotal
=
0
;
pRes
->
numOfClauseTotal
=
0
;
STableDataBlocks
*
pBlock
=
NULL
;
int32_t
ret
=
tscGetDataBlockFromList
(
pCmd
->
pTableBlockHashList
,
pTableMeta
->
id
.
uid
,
TSDB_PAYLOAD_SIZE
,
sizeof
(
SSubmitBlk
),
pTableMeta
->
tableInfo
.
rowSize
,
pTableMetaInfo
->
name
,
pTableMeta
,
&
pBlock
,
NULL
);
assert
(
ret
==
0
);
pBlock
->
size
=
sizeof
(
SSubmitBlk
)
+
pCmd
->
batchSize
*
pBlock
->
rowSize
;
SSubmitBlk
*
pBlk
=
(
SSubmitBlk
*
)
pBlock
->
pData
;
pBlk
->
numOfRows
=
pCmd
->
batchSize
;
pBlk
->
dataLen
=
0
;
pBlk
->
uid
=
pTableMeta
->
id
.
uid
;
pBlk
->
tid
=
pTableMeta
->
id
.
tid
;
int
code
=
tscMergeTableDataBlocks
(
stmt
->
pSql
,
false
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
return
code
;
}
pRes
->
qhandle
=
0
;
STableDataBlocks
*
pDataBlock
=
taosArrayGetP
(
pCmd
->
pDataBlocks
,
0
);
code
=
tscCopyDataBlockToPayload
(
stmt
->
pSql
,
pDataBlock
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
return
code
;
}
pSql
->
cmd
.
insertType
=
0
;
pSql
->
fetchFp
=
waitForQueryRsp
;
pSql
->
fp
=
(
void
(
*
)())
tscHandleMultivnodeInsert
;
SSqlObj
*
pSql
=
stmt
->
pSql
;
SSqlRes
*
pRes
=
&
pSql
->
res
;
pRes
->
numOfRows
=
0
;
pRes
->
numOfTotal
=
0
;
tsc
DoQuery
(
pSql
);
tsc
ProcessSql
(
pSql
);
// wait for the callback function to post the semaphore
tsem_wait
(
&
pSql
->
rspSem
);
return
pSql
->
res
.
code
;
// data block reset
pCmd
->
batchSize
=
0
;
for
(
int32_t
i
=
0
;
i
<
pCmd
->
numOfTables
;
++
i
)
{
if
(
pCmd
->
pTableNameList
&&
pCmd
->
pTableNameList
[
i
])
{
tfree
(
pCmd
->
pTableNameList
[
i
]);
}
}
pCmd
->
numOfTables
=
0
;
tfree
(
pCmd
->
pTableNameList
);
pCmd
->
pDataBlocks
=
tscDestroyBlockArrayList
(
pCmd
->
pDataBlocks
);
return
pSql
->
res
.
code
;
}
////////////////////////////////////////////////////////////////////////////////
...
...
@@ -867,11 +863,11 @@ TAOS_STMT* taos_stmt_init(TAOS* taos) {
}
tsem_init
(
&
pSql
->
rspSem
,
0
,
0
);
pSql
->
signature
=
pSql
;
pSql
->
pTscObj
=
pObj
;
pSql
->
maxRetry
=
TSDB_MAX_REPLICA
;
pSql
->
signature
=
pSql
;
pSql
->
pTscObj
=
pObj
;
pSql
->
maxRetry
=
TSDB_MAX_REPLICA
;
pStmt
->
pSql
=
pSql
;
pStmt
->
pSql
=
pSql
;
return
pStmt
;
}
...
...
@@ -890,7 +886,9 @@ int taos_stmt_prepare(TAOS_STMT* stmt, const char* sql, unsigned long length) {
SSqlRes
*
pRes
=
&
pSql
->
res
;
pSql
->
param
=
(
void
*
)
pSql
;
pSql
->
fp
=
waitForQueryRsp
;
pSql
->
cmd
.
insertType
=
TSDB_QUERY_TYPE_STMT_INSERT
;
pSql
->
fetchFp
=
waitForQueryRsp
;
pCmd
->
insertType
=
TSDB_QUERY_TYPE_STMT_INSERT
;
if
(
TSDB_CODE_SUCCESS
!=
tscAllocPayload
(
pCmd
,
TSDB_DEFAULT_PAYLOAD_SIZE
))
{
tscError
(
"%p failed to malloc payload buffer"
,
pSql
);
...
...
@@ -956,8 +954,9 @@ int taos_stmt_bind_param(TAOS_STMT* stmt, TAOS_BIND* bind) {
STscStmt
*
pStmt
=
(
STscStmt
*
)
stmt
;
if
(
pStmt
->
isInsert
)
{
return
insertStmtBindParam
(
pStmt
,
bind
);
}
else
{
return
normalStmtBindParam
(
pStmt
,
bind
);
}
return
normalStmtBindParam
(
pStmt
,
bind
);
}
int
taos_stmt_add_batch
(
TAOS_STMT
*
stmt
)
{
...
...
@@ -981,7 +980,7 @@ int taos_stmt_execute(TAOS_STMT* stmt) {
STscStmt
*
pStmt
=
(
STscStmt
*
)
stmt
;
if
(
pStmt
->
isInsert
)
{
ret
=
insertStmtExecute
(
pStmt
);
}
else
{
}
else
{
// normal stmt query
char
*
sql
=
normalStmtBuildSql
(
pStmt
);
if
(
sql
==
NULL
)
{
ret
=
TSDB_CODE_TSC_OUT_OF_MEMORY
;
...
...
@@ -995,6 +994,7 @@ int taos_stmt_execute(TAOS_STMT* stmt) {
free
(
sql
);
}
}
return
ret
;
}
...
...
src/client/src/tscSQLParser.c
浏览文件 @
c1b456be
...
...
@@ -229,7 +229,7 @@ static int32_t handlePassword(SSqlCmd* pCmd, SStrToken* pPwd) {
}
int32_t
tscToSQLCmd
(
SSqlObj
*
pSql
,
struct
SSqlInfo
*
pInfo
)
{
if
(
pInfo
==
NULL
||
pSql
==
NULL
||
pSql
->
signature
!=
pSql
)
{
if
(
pInfo
==
NULL
||
pSql
==
NULL
)
{
return
TSDB_CODE_TSC_APP_ERROR
;
}
...
...
@@ -642,7 +642,11 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
}
pSql
->
cmd
.
parseFinished
=
1
;
return
tscBuildMsg
[
pCmd
->
command
](
pSql
,
pInfo
);
if
(
tscBuildMsg
[
pCmd
->
command
]
!=
NULL
)
{
return
tscBuildMsg
[
pCmd
->
command
](
pSql
,
pInfo
);
}
else
{
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
"not support sql expression"
);
}
}
/*
...
...
@@ -1738,7 +1742,7 @@ static int32_t setExprInfoForFunctions(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SS
return
-
1
;
}
else
{
type
=
TSDB_DATA_TYPE_DOUBLE
;
bytes
=
tDataType
Desc
[
type
].
nSize
;
bytes
=
tDataType
s
[
type
].
bytes
;
}
}
else
{
type
=
pSchema
->
type
;
...
...
@@ -1844,7 +1848,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
}
index
=
(
SColumnIndex
){
0
,
PRIMARYKEY_TIMESTAMP_COL_INDEX
};
int32_t
size
=
tDataType
Desc
[
TSDB_DATA_TYPE_BIGINT
].
nSize
;
int32_t
size
=
tDataType
s
[
TSDB_DATA_TYPE_BIGINT
].
bytes
;
pExpr
=
tscSqlExprAppend
(
pQueryInfo
,
functionID
,
&
index
,
TSDB_DATA_TYPE_BIGINT
,
size
,
getNewResColId
(
pQueryInfo
),
size
,
false
);
}
else
if
(
sqlOptr
==
TK_INTEGER
)
{
// select count(1) from table1
char
buf
[
8
]
=
{
0
};
...
...
@@ -1856,7 +1860,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
}
if
(
val
==
1
)
{
index
=
(
SColumnIndex
){
0
,
PRIMARYKEY_TIMESTAMP_COL_INDEX
};
int32_t
size
=
tDataType
Desc
[
TSDB_DATA_TYPE_BIGINT
].
nSize
;
int32_t
size
=
tDataType
s
[
TSDB_DATA_TYPE_BIGINT
].
bytes
;
pExpr
=
tscSqlExprAppend
(
pQueryInfo
,
functionID
,
&
index
,
TSDB_DATA_TYPE_BIGINT
,
size
,
getNewResColId
(
pQueryInfo
),
size
,
false
);
}
else
{
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg3
);
...
...
@@ -1876,12 +1880,12 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
isTag
=
true
;
}
int32_t
size
=
tDataType
Desc
[
TSDB_DATA_TYPE_BIGINT
].
nSize
;
int32_t
size
=
tDataType
s
[
TSDB_DATA_TYPE_BIGINT
].
bytes
;
pExpr
=
tscSqlExprAppend
(
pQueryInfo
,
functionID
,
&
index
,
TSDB_DATA_TYPE_BIGINT
,
size
,
getNewResColId
(
pQueryInfo
),
size
,
isTag
);
}
}
else
{
// count(*) is equalled to count(primary_timestamp_key)
index
=
(
SColumnIndex
){
0
,
PRIMARYKEY_TIMESTAMP_COL_INDEX
};
int32_t
size
=
tDataType
Desc
[
TSDB_DATA_TYPE_BIGINT
].
nSize
;
int32_t
size
=
tDataType
s
[
TSDB_DATA_TYPE_BIGINT
].
bytes
;
pExpr
=
tscSqlExprAppend
(
pQueryInfo
,
functionID
,
&
index
,
TSDB_DATA_TYPE_BIGINT
,
size
,
getNewResColId
(
pQueryInfo
),
size
,
false
);
}
...
...
@@ -4510,6 +4514,8 @@ int32_t parseFillClause(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SQuerySQL* pQuery
}
}
else
if
(
strncasecmp
(
pItem
->
pVar
.
pz
,
"prev"
,
4
)
==
0
&&
pItem
->
pVar
.
nLen
==
4
)
{
pQueryInfo
->
fillType
=
TSDB_FILL_PREV
;
}
else
if
(
strncasecmp
(
pItem
->
pVar
.
pz
,
"next"
,
4
)
==
0
&&
pItem
->
pVar
.
nLen
==
4
)
{
pQueryInfo
->
fillType
=
TSDB_FILL_NEXT
;
}
else
if
(
strncasecmp
(
pItem
->
pVar
.
pz
,
"linear"
,
6
)
==
0
&&
pItem
->
pVar
.
nLen
==
6
)
{
pQueryInfo
->
fillType
=
TSDB_FILL_LINEAR
;
}
else
if
(
strncasecmp
(
pItem
->
pVar
.
pz
,
"value"
,
5
)
==
0
&&
pItem
->
pVar
.
nLen
==
5
)
{
...
...
@@ -4869,7 +4875,7 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
char
name1
[
128
]
=
{
0
};
strncpy
(
name1
,
pItem
->
pVar
.
pz
,
pItem
->
pVar
.
nLen
);
TAOS_FIELD
f
=
tscCreateField
(
TSDB_DATA_TYPE_INT
,
name1
,
tDataType
Desc
[
TSDB_DATA_TYPE_INT
].
nSize
);
TAOS_FIELD
f
=
tscCreateField
(
TSDB_DATA_TYPE_INT
,
name1
,
tDataType
s
[
TSDB_DATA_TYPE_INT
].
bytes
);
tscFieldInfoAppend
(
&
pQueryInfo
->
fieldsInfo
,
&
f
);
}
else
if
(
pAlterSQL
->
type
==
TSDB_ALTER_TABLE_CHANGE_TAG_COLUMN
)
{
SArray
*
pVarList
=
pAlterSQL
->
varList
;
...
...
@@ -4905,14 +4911,14 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
char
name
[
TSDB_COL_NAME_LEN
]
=
{
0
};
strncpy
(
name
,
pItem
->
pVar
.
pz
,
pItem
->
pVar
.
nLen
);
TAOS_FIELD
f
=
tscCreateField
(
TSDB_DATA_TYPE_INT
,
name
,
tDataType
Desc
[
TSDB_DATA_TYPE_INT
].
nSize
);
TAOS_FIELD
f
=
tscCreateField
(
TSDB_DATA_TYPE_INT
,
name
,
tDataType
s
[
TSDB_DATA_TYPE_INT
].
bytes
);
tscFieldInfoAppend
(
&
pQueryInfo
->
fieldsInfo
,
&
f
);
pItem
=
taosArrayGet
(
pVarList
,
1
);
memset
(
name
,
0
,
tListLen
(
name
));
strncpy
(
name
,
pItem
->
pVar
.
pz
,
pItem
->
pVar
.
nLen
);
f
=
tscCreateField
(
TSDB_DATA_TYPE_INT
,
name
,
tDataType
Desc
[
TSDB_DATA_TYPE_INT
].
nSize
);
f
=
tscCreateField
(
TSDB_DATA_TYPE_INT
,
name
,
tDataType
s
[
TSDB_DATA_TYPE_INT
].
bytes
);
tscFieldInfoAppend
(
&
pQueryInfo
->
fieldsInfo
,
&
f
);
}
else
if
(
pAlterSQL
->
type
==
TSDB_ALTER_TABLE_UPDATE_TAG_VAL
)
{
// Note: update can only be applied to table not super table.
...
...
@@ -4987,7 +4993,7 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
int32_t
len
=
0
;
if
(
pTagsSchema
->
type
!=
TSDB_DATA_TYPE_BINARY
&&
pTagsSchema
->
type
!=
TSDB_DATA_TYPE_NCHAR
)
{
len
=
tDataType
Desc
[
pTagsSchema
->
type
].
nSize
;
len
=
tDataType
s
[
pTagsSchema
->
type
].
bytes
;
}
else
{
len
=
varDataTLen
(
pUpdateMsg
->
data
+
schemaLen
);
}
...
...
@@ -5034,7 +5040,7 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
char
name1
[
TSDB_COL_NAME_LEN
]
=
{
0
};
tstrncpy
(
name1
,
pItem
->
pVar
.
pz
,
sizeof
(
name1
));
TAOS_FIELD
f
=
tscCreateField
(
TSDB_DATA_TYPE_INT
,
name1
,
tDataType
Desc
[
TSDB_DATA_TYPE_INT
].
nSize
);
TAOS_FIELD
f
=
tscCreateField
(
TSDB_DATA_TYPE_INT
,
name1
,
tDataType
s
[
TSDB_DATA_TYPE_INT
].
bytes
);
tscFieldInfoAppend
(
&
pQueryInfo
->
fieldsInfo
,
&
f
);
}
...
...
@@ -5997,7 +6003,7 @@ int32_t doLocalQueryProcess(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SQuerySQL* pQ
SColumnIndex
ind
=
{
0
};
SSqlExpr
*
pExpr1
=
tscSqlExprAppend
(
pQueryInfo
,
TSDB_FUNC_TAG_DUMMY
,
&
ind
,
TSDB_DATA_TYPE_INT
,
tDataType
Desc
[
TSDB_DATA_TYPE_INT
].
nSize
,
getNewResColId
(
pQueryInfo
),
tDataTypeDesc
[
TSDB_DATA_TYPE_INT
].
nSize
,
false
);
tDataType
s
[
TSDB_DATA_TYPE_INT
].
bytes
,
getNewResColId
(
pQueryInfo
),
tDataTypes
[
TSDB_DATA_TYPE_INT
].
bytes
,
false
);
const
char
*
name
=
(
pExprList
->
a
[
0
].
aliasName
!=
NULL
)
?
pExprList
->
a
[
0
].
aliasName
:
functionsInfo
[
index
].
name
;
tstrncpy
(
pExpr1
->
aliasName
,
name
,
tListLen
(
pExpr1
->
aliasName
));
...
...
src/client/src/tscSchemaUtil.c
浏览文件 @
c1b456be
...
...
@@ -66,68 +66,6 @@ STableComInfo tscGetTableInfo(const STableMeta* pTableMeta) {
return
pTableMeta
->
tableInfo
;
}
static
bool
doValidateSchema
(
SSchema
*
pSchema
,
int32_t
numOfCols
,
int32_t
maxLen
)
{
int32_t
rowLen
=
0
;
for
(
int32_t
i
=
0
;
i
<
numOfCols
;
++
i
)
{
// 1. valid types
if
(
!
isValidDataType
(
pSchema
[
i
].
type
))
{
return
false
;
}
// 2. valid length for each type
if
(
pSchema
[
i
].
type
==
TSDB_DATA_TYPE_BINARY
)
{
if
(
pSchema
[
i
].
bytes
>
TSDB_MAX_BINARY_LEN
)
{
return
false
;
}
}
else
if
(
pSchema
[
i
].
type
==
TSDB_DATA_TYPE_NCHAR
)
{
if
(
pSchema
[
i
].
bytes
>
TSDB_MAX_NCHAR_LEN
)
{
return
false
;
}
}
else
{
if
(
pSchema
[
i
].
bytes
!=
tDataTypeDesc
[
pSchema
[
i
].
type
].
nSize
)
{
return
false
;
}
}
// 3. valid column names
for
(
int32_t
j
=
i
+
1
;
j
<
numOfCols
;
++
j
)
{
if
(
strncasecmp
(
pSchema
[
i
].
name
,
pSchema
[
j
].
name
,
sizeof
(
pSchema
[
i
].
name
)
-
1
)
==
0
)
{
return
false
;
}
}
rowLen
+=
pSchema
[
i
].
bytes
;
}
return
rowLen
<=
maxLen
;
}
bool
isValidSchema
(
struct
SSchema
*
pSchema
,
int32_t
numOfCols
,
int32_t
numOfTags
)
{
if
(
!
VALIDNUMOFCOLS
(
numOfCols
))
{
return
false
;
}
if
(
!
VALIDNUMOFTAGS
(
numOfTags
))
{
return
false
;
}
/* first column must be the timestamp, which is a primary key */
if
(
pSchema
[
0
].
type
!=
TSDB_DATA_TYPE_TIMESTAMP
)
{
return
false
;
}
if
(
!
doValidateSchema
(
pSchema
,
numOfCols
,
TSDB_MAX_BYTES_PER_ROW
))
{
return
false
;
}
if
(
!
doValidateSchema
(
&
pSchema
[
numOfCols
],
numOfTags
,
TSDB_MAX_TAGS_LEN
))
{
return
false
;
}
return
true
;
}
SSchema
*
tscGetTableColumnSchema
(
const
STableMeta
*
pTableMeta
,
int32_t
colIndex
)
{
assert
(
pTableMeta
!=
NULL
);
...
...
src/client/src/tscServer.c
浏览文件 @
c1b456be
...
...
@@ -25,8 +25,6 @@
#include "ttimer.h"
#include "tlockfree.h"
///SRpcCorEpSet tscMgmtEpSet;
int
(
*
tscBuildMsg
[
TSDB_SQL_MAX
])(
SSqlObj
*
pSql
,
SSqlInfo
*
pInfo
)
=
{
0
};
int
(
*
tscProcessMsgRsp
[
TSDB_SQL_MAX
])(
SSqlObj
*
pSql
);
...
...
@@ -341,7 +339,8 @@ void tscProcessMsgFromServer(SRpcMsg *rpcMsg, SRpcEpSet *pEpSet) {
if
(
pSql
->
retry
>
pSql
->
maxRetry
)
{
tscError
(
"%p max retry %d reached, give up"
,
pSql
,
pSql
->
maxRetry
);
}
else
{
// wait for a little bit moment and then retry, todo do not sleep in rpc callback thread
// wait for a little bit moment and then retry
// todo do not sleep in rpc callback thread, add this process into queueu to process
if
(
rpcMsg
->
code
==
TSDB_CODE_APP_NOT_READY
||
rpcMsg
->
code
==
TSDB_CODE_VND_INVALID_VGROUP_ID
)
{
int32_t
duration
=
getWaitingTimeInterval
(
pSql
->
retry
);
taosMsleep
(
duration
);
...
...
@@ -484,9 +483,9 @@ int tscProcessSql(SSqlObj *pSql) {
pSql
->
res
.
code
=
TSDB_CODE_TSC_APP_ERROR
;
return
pSql
->
res
.
code
;
}
}
else
if
(
pCmd
->
command
<
TSDB_SQL_LOCAL
)
{
}
else
if
(
pCmd
->
command
>=
TSDB_SQL_LOCAL
)
{
//pSql->epSet = tscMgmtEpSet;
}
else
{
// local handler
//
} else { // local handler
return
(
*
tscProcessMsgRsp
[
pCmd
->
command
])(
pSql
);
}
...
...
@@ -1157,7 +1156,7 @@ int32_t tscBuildDropTableMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
SCMDropTableMsg
*
pDropTableMsg
=
(
SCMDropTableMsg
*
)
pCmd
->
payload
;
STableMetaInfo
*
pTableMetaInfo
=
tscGetTableMetaInfoFromCmd
(
pCmd
,
pCmd
->
clauseIndex
,
0
);
strcpy
(
pDropTableMsg
->
table
Id
,
pTableMetaInfo
->
name
);
strcpy
(
pDropTableMsg
->
table
Fname
,
pTableMetaInfo
->
name
);
pDropTableMsg
->
igNotExists
=
pInfo
->
pDCLInfo
->
existsCheck
?
1
:
0
;
pCmd
->
msgType
=
TSDB_MSG_TYPE_CM_DROP_TABLE
;
...
...
@@ -1180,7 +1179,7 @@ int32_t tscBuildDropDnodeMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
return
TSDB_CODE_SUCCESS
;
}
int32_t
tscBuildDropUserMsg
(
SSqlObj
*
pSql
,
SSqlInfo
*
pInfo
)
{
int32_t
tscBuildDropUserMsg
(
SSqlObj
*
pSql
,
SSqlInfo
*
UNUSED_PARAM
(
pInfo
)
)
{
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
pCmd
->
payloadLen
=
sizeof
(
SDropUserMsg
);
pCmd
->
msgType
=
TSDB_MSG_TYPE_CM_DROP_USER
;
...
...
@@ -1347,7 +1346,7 @@ int tscBuildCreateTableMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
pMsg
+=
sizeof
(
SCreateTableMsg
);
SCreatedTableInfo
*
p
=
taosArrayGet
(
list
,
i
);
strcpy
(
pCreate
->
table
Id
,
p
->
fullname
);
strcpy
(
pCreate
->
table
Fname
,
p
->
fullname
);
pCreate
->
igExists
=
(
p
->
igExist
)
?
1
:
0
;
// use dbinfo from table id without modifying current db info
...
...
@@ -1360,7 +1359,7 @@ int tscBuildCreateTableMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
}
else
{
// create (super) table
pCreateTableMsg
->
numOfTables
=
htonl
(
1
);
// only one table will be created
strcpy
(
pCreateMsg
->
table
Id
,
pTableMetaInfo
->
name
);
strcpy
(
pCreateMsg
->
table
Fname
,
pTableMetaInfo
->
name
);
// use dbinfo from table id without modifying current db info
tscGetDBInfoFromTableFullName
(
pTableMetaInfo
->
name
,
pCreateMsg
->
db
);
...
...
@@ -1431,7 +1430,7 @@ int tscBuildAlterTableMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
SAlterTableMsg
*
pAlterTableMsg
=
(
SAlterTableMsg
*
)
pCmd
->
payload
;
tscGetDBInfoFromTableFullName
(
pTableMetaInfo
->
name
,
pAlterTableMsg
->
db
);
strcpy
(
pAlterTableMsg
->
table
Id
,
pTableMetaInfo
->
name
);
strcpy
(
pAlterTableMsg
->
table
Fname
,
pTableMetaInfo
->
name
);
pAlterTableMsg
->
type
=
htons
(
pAlterInfo
->
type
);
pAlterTableMsg
->
numOfCols
=
htons
(
tscNumOfFields
(
pQueryInfo
));
...
...
@@ -1630,7 +1629,7 @@ int tscBuildTableMetaMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
STableMetaInfo
*
pTableMetaInfo
=
tscGetMetaInfo
(
pQueryInfo
,
0
);
STableInfoMsg
*
pInfoMsg
=
(
STableInfoMsg
*
)
pCmd
->
payload
;
strcpy
(
pInfoMsg
->
table
Id
,
pTableMetaInfo
->
name
);
strcpy
(
pInfoMsg
->
table
Fname
,
pTableMetaInfo
->
name
);
pInfoMsg
->
createFlag
=
htons
(
pSql
->
cmd
.
autoCreated
?
1
:
0
);
char
*
pMsg
=
(
char
*
)
pInfoMsg
+
sizeof
(
STableInfoMsg
);
...
...
@@ -1799,7 +1798,7 @@ int tscProcessTableMetaRsp(SSqlObj *pSql) {
if
((
pMetaMsg
->
tableType
!=
TSDB_SUPER_TABLE
)
&&
(
pMetaMsg
->
tid
<=
0
||
pMetaMsg
->
vgroup
.
vgId
<
2
||
pMetaMsg
->
vgroup
.
numOfEps
<=
0
))
{
tscError
(
"invalid value in table numOfEps:%d, vgId:%d tid:%d, name:%s"
,
pMetaMsg
->
vgroup
.
numOfEps
,
pMetaMsg
->
vgroup
.
vgId
,
pMetaMsg
->
tid
,
pMetaMsg
->
table
Id
);
pMetaMsg
->
tid
,
pMetaMsg
->
table
Fname
);
return
TSDB_CODE_TSC_INVALID_VALUE
;
}
...
...
@@ -1831,12 +1830,16 @@ int tscProcessTableMetaRsp(SSqlObj *pSql) {
assert
(
isValidDataType
(
pSchema
->
type
));
pSchema
++
;
}
STableMeta
*
pTableMeta
=
tscCreateTableMetaFromMsg
(
pMetaMsg
);
STableMetaInfo
*
pTableMetaInfo
=
tscGetTableMetaInfoFromCmd
(
&
pSql
->
cmd
,
0
,
0
);
assert
(
pTableMetaInfo
->
pTableMeta
==
NULL
);
STableMeta
*
pTableMeta
=
tscCreateTableMetaFromMsg
(
pMetaMsg
);
if
(
!
isValidSchema
(
pTableMeta
->
schema
,
pTableMeta
->
tableInfo
.
numOfColumns
,
pTableMeta
->
tableInfo
.
numOfTags
))
{
tscError
(
"%p invalid table meta from mnode, name:%s"
,
pSql
,
pTableMetaInfo
->
name
);
return
TSDB_CODE_TSC_INVALID_VALUE
;
}
if
(
pTableMeta
->
tableType
==
TSDB_CHILD_TABLE
)
{
// check if super table hashmap or not
int32_t
len
=
(
int32_t
)
strnlen
(
pTableMeta
->
sTableName
,
TSDB_TABLE_FNAME_LEN
);
...
...
@@ -2097,7 +2100,7 @@ int tscProcessShowRsp(SSqlObj *pSql) {
return
0
;
}
static
void
createH
B
Obj
(
STscObj
*
pObj
)
{
static
void
createH
b
Obj
(
STscObj
*
pObj
)
{
if
(
pObj
->
hbrid
!=
0
)
{
return
;
}
...
...
@@ -2160,7 +2163,7 @@ int tscProcessConnectRsp(SSqlObj *pSql) {
pObj
->
superAuth
=
pConnect
->
superAuth
;
pObj
->
connId
=
htonl
(
pConnect
->
connId
);
createH
B
Obj
(
pObj
);
createH
b
Obj
(
pObj
);
//launch a timer to send heartbeat to maintain the connection and send status to mnode
taosTmrReset
(
tscProcessActivityTimer
,
tsShellActivityTimer
*
500
,
(
void
*
)
pObj
->
rid
,
tscTmr
,
&
pObj
->
pTimer
);
...
...
src/client/src/tscSql.c
浏览文件 @
c1b456be
...
...
@@ -781,6 +781,7 @@ bool taos_is_null(TAOS_RES *res, int32_t row, int32_t col) {
int
taos_print_row
(
char
*
str
,
TAOS_ROW
row
,
TAOS_FIELD
*
fields
,
int
num_fields
)
{
int
len
=
0
;
for
(
int
i
=
0
;
i
<
num_fields
;
++
i
)
{
if
(
i
>
0
)
{
str
[
len
++
]
=
' '
;
...
...
@@ -838,13 +839,15 @@ int taos_print_row(char *str, TAOS_ROW row, TAOS_FIELD *fields, int num_fields)
case
TSDB_DATA_TYPE_BINARY
:
case
TSDB_DATA_TYPE_NCHAR
:
{
size_t
xlen
=
0
;
for
(
xlen
=
0
;
xlen
<
fields
[
i
].
bytes
-
VARSTR_HEADER_SIZE
;
xlen
++
)
{
char
c
=
((
char
*
)
row
[
i
])[
xlen
]
;
if
(
c
==
0
)
break
;
str
[
len
++
]
=
c
;
int32_t
charLen
=
varDataLen
((
char
*
)
row
[
i
]
-
VARSTR_HEADER_SIZE
)
;
if
(
fields
[
i
].
type
==
TSDB_DATA_TYPE_BINARY
)
{
assert
(
charLen
<=
fields
[
i
].
bytes
)
;
}
else
{
assert
(
charLen
<=
fields
[
i
].
bytes
*
TSDB_NCHAR_SIZE
)
;
}
str
[
len
]
=
0
;
memcpy
(
str
+
len
,
row
[
i
],
charLen
);
len
+=
charLen
;
}
break
;
case
TSDB_DATA_TYPE_TIMESTAMP
:
...
...
src/client/src/tscUtil.c
浏览文件 @
c1b456be
...
...
@@ -603,6 +603,7 @@ int32_t tscCopyDataBlockToPayload(SSqlObj* pSql, STableDataBlocks* pDataBlock) {
assert
(
pCmd
->
numOfClause
==
1
);
STableMetaInfo
*
pTableMetaInfo
=
tscGetTableMetaInfoFromCmd
(
pCmd
,
pCmd
->
clauseIndex
,
0
);
// todo refactor
// set the correct table meta object, the table meta has been locked in pDataBlocks, so it must be in the cache
if
(
pTableMetaInfo
->
pTableMeta
!=
pDataBlock
->
pTableMeta
)
{
tstrncpy
(
pTableMetaInfo
->
name
,
pDataBlock
->
tableName
,
sizeof
(
pTableMetaInfo
->
name
));
...
...
@@ -689,7 +690,6 @@ int32_t tscCreateDataBlock(size_t initialSize, int32_t rowSize, int32_t startOff
int32_t
tscGetDataBlockFromList
(
SHashObj
*
pHashList
,
int64_t
id
,
int32_t
size
,
int32_t
startOffset
,
int32_t
rowSize
,
const
char
*
tableId
,
STableMeta
*
pTableMeta
,
STableDataBlocks
**
dataBlocks
,
SArray
*
pBlockList
)
{
*
dataBlocks
=
NULL
;
STableDataBlocks
**
t1
=
(
STableDataBlocks
**
)
taosHashGet
(
pHashList
,
(
const
char
*
)
&
id
,
sizeof
(
id
));
if
(
t1
!=
NULL
)
{
*
dataBlocks
=
*
t1
;
...
...
@@ -785,9 +785,13 @@ static int32_t getRowExpandSize(STableMeta* pTableMeta) {
return
result
;
}
static
void
extractTableNameList
(
SSqlCmd
*
pCmd
)
{
static
void
extractTableNameList
(
SSqlCmd
*
pCmd
,
bool
freeBlockMap
)
{
pCmd
->
numOfTables
=
(
int32_t
)
taosHashGetSize
(
pCmd
->
pTableBlockHashList
);
pCmd
->
pTableNameList
=
calloc
(
pCmd
->
numOfTables
,
POINTER_BYTES
);
if
(
pCmd
->
pTableNameList
==
NULL
)
{
pCmd
->
pTableNameList
=
calloc
(
pCmd
->
numOfTables
,
POINTER_BYTES
);
}
else
{
memset
(
pCmd
->
pTableNameList
,
0
,
pCmd
->
numOfTables
*
POINTER_BYTES
);
}
STableDataBlocks
**
p1
=
taosHashIterate
(
pCmd
->
pTableBlockHashList
,
NULL
);
int32_t
i
=
0
;
...
...
@@ -797,10 +801,12 @@ static void extractTableNameList(SSqlCmd* pCmd) {
p1
=
taosHashIterate
(
pCmd
->
pTableBlockHashList
,
p1
);
}
pCmd
->
pTableBlockHashList
=
tscDestroyBlockHashTable
(
pCmd
->
pTableBlockHashList
);
if
(
freeBlockMap
)
{
pCmd
->
pTableBlockHashList
=
tscDestroyBlockHashTable
(
pCmd
->
pTableBlockHashList
);
}
}
int32_t
tscMergeTableDataBlocks
(
SSqlObj
*
pSql
)
{
int32_t
tscMergeTableDataBlocks
(
SSqlObj
*
pSql
,
bool
freeBlockMap
)
{
const
int
INSERT_HEAD_SIZE
=
sizeof
(
SMsgDesc
)
+
sizeof
(
SSubmitMsg
);
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
...
...
@@ -880,7 +886,7 @@ int32_t tscMergeTableDataBlocks(SSqlObj* pSql) {
pOneTableBlock
=
*
p
;
}
extractTableNameList
(
pCmd
);
extractTableNameList
(
pCmd
,
freeBlockMap
);
// free the table data blocks;
pCmd
->
pDataBlocks
=
pVnodeDataBlockList
;
...
...
@@ -1915,7 +1921,7 @@ void registerSqlObj(SSqlObj* pSql) {
tscDebug
(
"%p new SqlObj from %p, total in tscObj:%d, total:%d"
,
pSql
,
pSql
->
pTscObj
,
num
,
total
);
}
SSqlObj
*
createSimpleSubObj
(
SSqlObj
*
pSql
,
void
(
*
fp
)()
,
void
*
param
,
int32_t
cmd
)
{
SSqlObj
*
createSimpleSubObj
(
SSqlObj
*
pSql
,
__async_cb_func_t
fp
,
void
*
param
,
int32_t
cmd
)
{
SSqlObj
*
pNew
=
(
SSqlObj
*
)
calloc
(
1
,
sizeof
(
SSqlObj
));
if
(
pNew
==
NULL
)
{
tscError
(
"%p new subquery failed, tableIndex:%d"
,
pSql
,
0
);
...
...
@@ -2000,7 +2006,7 @@ static void doSetSqlExprAndResultFieldInfo(SQueryInfo* pNewQueryInfo, int64_t ui
tscFieldInfoUpdateOffset
(
pNewQueryInfo
);
}
SSqlObj
*
createSubqueryObj
(
SSqlObj
*
pSql
,
int16_t
tableIndex
,
void
(
*
fp
)()
,
void
*
param
,
int32_t
cmd
,
SSqlObj
*
pPrevSql
)
{
SSqlObj
*
createSubqueryObj
(
SSqlObj
*
pSql
,
int16_t
tableIndex
,
__async_cb_func_t
fp
,
void
*
param
,
int32_t
cmd
,
SSqlObj
*
pPrevSql
)
{
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SSqlObj
*
pNew
=
(
SSqlObj
*
)
calloc
(
1
,
sizeof
(
SSqlObj
));
...
...
@@ -2196,7 +2202,7 @@ void tscDoQuery(SSqlObj* pSql) {
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
pCmd
->
clauseIndex
);
uint16_t
type
=
pQueryInfo
->
type
;
if
(
pSql
->
fp
==
(
void
(
*
)())
tscHandleMultivnodeInsert
)
{
// multi-vnodes insertion
if
(
TSDB_QUERY_HAS_TYPE
(
type
,
TSDB_QUERY_TYPE_INSERT
)
)
{
// multi-vnodes insertion
tscHandleMultivnodeInsert
(
pSql
);
return
;
}
...
...
src/client/tests/
resultField
Test.cpp
→
src/client/tests/
cli
Test.cpp
浏览文件 @
c1b456be
...
...
@@ -2,15 +2,117 @@
#include <iostream>
#include "taos.h"
#include "tglobal.h"
namespace
{
static
int64_t
start_ts
=
1433955661000
;
void
stmtInsertTest
()
{
TAOS
*
conn
=
taos_connect
(
"ubuntu"
,
"root"
,
"taosdata"
,
0
,
0
);
if
(
conn
==
NULL
)
{
printf
(
"Failed to connect to DB, reason:%s"
,
taos_errstr
(
conn
));
exit
(
-
1
);
}
TAOS_RES
*
res
=
taos_query
(
conn
,
"use test"
);
taos_free_result
(
res
);
const
char
*
sql
=
"insert into t1 values(?, ?, ?, ?)"
;
TAOS_STMT
*
stmt
=
taos_stmt_init
(
conn
);
int32_t
ret
=
taos_stmt_prepare
(
stmt
,
sql
,
0
);
ASSERT_EQ
(
ret
,
0
);
//ts timestamp, k int, a binary(11), b nchar(4)
struct
{
int64_t
ts
;
int
k
;
char
*
a
;
char
*
b
;
}
v
=
{
0
};
TAOS_BIND
params
[
4
];
params
[
0
].
buffer_type
=
TSDB_DATA_TYPE_TIMESTAMP
;
params
[
0
].
buffer_length
=
sizeof
(
v
.
ts
);
params
[
0
].
buffer
=
&
v
.
ts
;
params
[
0
].
length
=
&
params
[
0
].
buffer_length
;
params
[
0
].
is_null
=
NULL
;
params
[
1
].
buffer_type
=
TSDB_DATA_TYPE_INT
;
params
[
1
].
buffer_length
=
sizeof
(
v
.
k
);
params
[
1
].
buffer
=
&
v
.
k
;
params
[
1
].
length
=
&
params
[
1
].
buffer_length
;
params
[
1
].
is_null
=
NULL
;
params
[
2
].
buffer_type
=
TSDB_DATA_TYPE_BINARY
;
params
[
2
].
buffer_length
=
sizeof
(
v
.
a
);
params
[
2
].
buffer
=
&
v
.
a
;
params
[
2
].
is_null
=
NULL
;
params
[
3
].
buffer_type
=
TSDB_DATA_TYPE_NCHAR
;
params
[
3
].
buffer_length
=
sizeof
(
v
.
b
);
params
[
3
].
buffer
=
&
v
.
b
;
params
[
3
].
is_null
=
NULL
;
v
.
ts
=
start_ts
+
20
;
v
.
k
=
123
;
char
*
str
=
"abc"
;
uintptr_t
len
=
strlen
(
str
);
v
.
a
=
str
;
params
[
2
].
length
=
&
len
;
params
[
2
].
buffer_length
=
len
;
params
[
2
].
buffer
=
str
;
char
*
nstr
=
"999"
;
uintptr_t
len1
=
strlen
(
nstr
);
v
.
b
=
nstr
;
params
[
3
].
buffer_length
=
len1
;
params
[
3
].
buffer
=
nstr
;
params
[
3
].
length
=
&
len1
;
taos_stmt_bind_param
(
stmt
,
params
);
taos_stmt_add_batch
(
stmt
);
if
(
taos_stmt_execute
(
stmt
)
!=
0
)
{
printf
(
"
\033
[31mfailed to execute insert statement.
\033
[0m
\n
"
);
return
;
}
v
.
ts
=
start_ts
+
30
;
v
.
k
=
911
;
str
=
"92"
;
len
=
strlen
(
str
);
params
[
2
].
length
=
&
len
;
params
[
2
].
buffer_length
=
len
;
params
[
2
].
buffer
=
str
;
nstr
=
"1920"
;
len1
=
strlen
(
nstr
);
params
[
3
].
buffer_length
=
len1
;
params
[
3
].
buffer
=
nstr
;
params
[
3
].
length
=
&
len1
;
taos_stmt_bind_param
(
stmt
,
params
);
taos_stmt_add_batch
(
stmt
);
ret
=
taos_stmt_execute
(
stmt
);
if
(
ret
!=
0
)
{
printf
(
"%p
\n
"
,
ret
);
printf
(
"
\033
[31mfailed to execute insert statement.
\033
[0m
\n
"
);
return
;
}
taos_stmt_close
(
stmt
);
taos_close
(
conn
);
}
/* test parse time function */
TEST
(
testCase
,
result_field_test
)
{
taos_options
(
TSDB_OPTION_CONFIGDIR
,
"~/first/cfg"
);
taos_init
();
void
validateResultFields
()
{
TAOS
*
conn
=
taos_connect
(
"ubuntu"
,
"root"
,
"taosdata"
,
0
,
0
);
if
(
conn
==
NULL
)
{
printf
(
"Failed to connect to DB, reason:%s"
,
taos_errstr
(
conn
));
...
...
@@ -134,5 +236,31 @@ TEST(testCase, result_field_test) {
ASSERT_STREQ
(
fields
[
6
].
name
,
"first(ts)"
);
taos_free_result
(
res
);
// update the configure parameter, the result field name will be changed
tsKeepOriginalColumnName
=
1
;
res
=
taos_query
(
conn
,
"select first(ts, a, k, k, b, b, ts) from t1"
);
ASSERT_EQ
(
taos_num_fields
(
res
),
7
);
fields
=
taos_fetch_fields
(
res
);
ASSERT_EQ
(
fields
[
0
].
bytes
,
8
);
ASSERT_EQ
(
fields
[
0
].
type
,
TSDB_DATA_TYPE_TIMESTAMP
);
ASSERT_STREQ
(
fields
[
0
].
name
,
"ts"
);
ASSERT_EQ
(
fields
[
2
].
bytes
,
4
);
ASSERT_EQ
(
fields
[
2
].
type
,
TSDB_DATA_TYPE_INT
);
ASSERT_STREQ
(
fields
[
2
].
name
,
"k"
);
taos_free_result
(
res
);
taos_close
(
conn
);
}
}
/* test parse time function */
TEST
(
testCase
,
result_field_test
)
{
taos_options
(
TSDB_OPTION_CONFIGDIR
,
"~/first/cfg"
);
taos_init
();
validateResultFields
();
stmtInsertTest
();
}
src/common/inc/tdataformat.h
浏览文件 @
c1b456be
...
...
@@ -20,7 +20,7 @@
#include <string.h>
#include "talgo.h"
#include "t
aosdef
.h"
#include "t
type
.h"
#include "tutil.h"
#ifdef __cplusplus
...
...
src/common/inc/tglobal.h
浏览文件 @
c1b456be
...
...
@@ -179,7 +179,7 @@ extern int32_t tsLogKeepDays;
extern
int32_t
dDebugFlag
;
extern
int32_t
vDebugFlag
;
extern
int32_t
mDebugFlag
;
extern
int32_t
cDebugFlag
;
extern
u
int32_t
cDebugFlag
;
extern
int32_t
jniDebugFlag
;
extern
int32_t
tmrDebugFlag
;
extern
int32_t
sdbDebugFlag
;
...
...
src/common/inc/tname.h
浏览文件 @
c1b456be
...
...
@@ -39,4 +39,18 @@ SColumnFilterInfo* tscFilterInfoClone(const SColumnFilterInfo* src, int32_t numO
SSchema
tscGetTbnameColumnSchema
();
/**
* check if the schema is valid or not, including following aspects:
* 1. number of columns
* 2. column types
* 3. column length
* 4. column names
* 5. total length
*
* @param pSchema
* @param numOfCols
* @return
*/
bool
isValidSchema
(
struct
SSchema
*
pSchema
,
int32_t
numOfCols
,
int32_t
numOfTags
);
#endif // TDENGINE_NAME_H
src/common/src/tglobal.c
浏览文件 @
c1b456be
...
...
@@ -219,7 +219,7 @@ int32_t mDebugFlag = 131;
int32_t
sdbDebugFlag
=
131
;
int32_t
dDebugFlag
=
135
;
int32_t
vDebugFlag
=
135
;
int32_t
cDebugFlag
=
131
;
u
int32_t
cDebugFlag
=
131
;
int32_t
jniDebugFlag
=
131
;
int32_t
odbcDebugFlag
=
131
;
int32_t
httpDebugFlag
=
131
;
...
...
src/common/src/tname.c
浏览文件 @
c1b456be
...
...
@@ -6,6 +6,10 @@
#include "ttokendef.h"
#include "tvariant.h"
#define VALIDNUMOFCOLS(x) ((x) >= TSDB_MIN_COLUMNS && (x) <= TSDB_MAX_COLUMNS)
#define VALIDNUMOFTAGS(x) ((x) >= 0 && (x) <= TSDB_MAX_TAGS)
// todo refactor
UNUSED_FUNC
static
FORCE_INLINE
const
char
*
skipSegments
(
const
char
*
input
,
char
delim
,
int32_t
num
)
{
for
(
int32_t
i
=
0
;
i
<
num
;
++
i
)
{
...
...
@@ -62,7 +66,7 @@ SSchema tGetUserSpecifiedColumnSchema(tVariant* pVal, SStrToken* exprStr, const
if
(
s
.
type
==
TSDB_DATA_TYPE_BINARY
||
s
.
type
==
TSDB_DATA_TYPE_NCHAR
)
{
s
.
bytes
=
(
int16_t
)(
pVal
->
nLen
+
VARSTR_HEADER_SIZE
);
}
else
{
s
.
bytes
=
tDataType
Desc
[
pVal
->
nType
].
nSize
;
s
.
bytes
=
tDataType
s
[
pVal
->
nType
].
bytes
;
}
s
.
colId
=
TSDB_UD_COLUMN_INDEX
;
...
...
@@ -206,3 +210,65 @@ SSchema tscGetTbnameColumnSchema() {
strcpy
(
s
.
name
,
TSQL_TBNAME_L
);
return
s
;
}
static
bool
doValidateSchema
(
SSchema
*
pSchema
,
int32_t
numOfCols
,
int32_t
maxLen
)
{
int32_t
rowLen
=
0
;
for
(
int32_t
i
=
0
;
i
<
numOfCols
;
++
i
)
{
// 1. valid types
if
(
!
isValidDataType
(
pSchema
[
i
].
type
))
{
return
false
;
}
// 2. valid length for each type
if
(
pSchema
[
i
].
type
==
TSDB_DATA_TYPE_BINARY
)
{
if
(
pSchema
[
i
].
bytes
>
TSDB_MAX_BINARY_LEN
)
{
return
false
;
}
}
else
if
(
pSchema
[
i
].
type
==
TSDB_DATA_TYPE_NCHAR
)
{
if
(
pSchema
[
i
].
bytes
>
TSDB_MAX_NCHAR_LEN
)
{
return
false
;
}
}
else
{
if
(
pSchema
[
i
].
bytes
!=
tDataTypes
[
pSchema
[
i
].
type
].
bytes
)
{
return
false
;
}
}
// 3. valid column names
for
(
int32_t
j
=
i
+
1
;
j
<
numOfCols
;
++
j
)
{
if
(
strncasecmp
(
pSchema
[
i
].
name
,
pSchema
[
j
].
name
,
sizeof
(
pSchema
[
i
].
name
)
-
1
)
==
0
)
{
return
false
;
}
}
rowLen
+=
pSchema
[
i
].
bytes
;
}
return
rowLen
<=
maxLen
;
}
bool
isValidSchema
(
struct
SSchema
*
pSchema
,
int32_t
numOfCols
,
int32_t
numOfTags
)
{
if
(
!
VALIDNUMOFCOLS
(
numOfCols
))
{
return
false
;
}
if
(
!
VALIDNUMOFTAGS
(
numOfTags
))
{
return
false
;
}
/* first column must be the timestamp, which is a primary key */
if
(
pSchema
[
0
].
type
!=
TSDB_DATA_TYPE_TIMESTAMP
)
{
return
false
;
}
if
(
!
doValidateSchema
(
pSchema
,
numOfCols
,
TSDB_MAX_BYTES_PER_ROW
))
{
return
false
;
}
if
(
!
doValidateSchema
(
&
pSchema
[
numOfCols
],
numOfTags
,
TSDB_MAX_TAGS_LEN
))
{
return
false
;
}
return
true
;
}
src/common/src/ttypes.c
浏览文件 @
c1b456be
...
...
@@ -14,7 +14,7 @@
*/
#include "os.h"
#include "t
aosdef
.h"
#include "t
type
.h"
#include "ttokendef.h"
#include "tscompression.h"
...
...
@@ -367,7 +367,7 @@ static void getStatics_nchr(const void *pData, int32_t numOfRow, int64_t *min, i
*
maxIndex
=
0
;
}
tDataTypeDescriptor
tDataType
Desc
[
15
]
=
{
tDataTypeDescriptor
tDataType
s
[
15
]
=
{
{
TSDB_DATA_TYPE_NULL
,
6
,
1
,
"NOTYPE"
,
NULL
,
NULL
,
NULL
},
{
TSDB_DATA_TYPE_BOOL
,
4
,
CHAR_BYTES
,
"BOOL"
,
tsCompressBool
,
tsDecompressBool
,
getStatics_bool
},
{
TSDB_DATA_TYPE_TINYINT
,
7
,
CHAR_BYTES
,
"TINYINT"
,
tsCompressTinyint
,
tsDecompressTinyint
,
getStatics_i8
},
...
...
@@ -423,58 +423,58 @@ void setNullN(char *val, int32_t type, int32_t bytes, int32_t numOfElems) {
switch
(
type
)
{
case
TSDB_DATA_TYPE_BOOL
:
for
(
int32_t
i
=
0
;
i
<
numOfElems
;
++
i
)
{
*
(
uint8_t
*
)(
val
+
i
*
tDataType
Desc
[
type
].
nSize
)
=
TSDB_DATA_BOOL_NULL
;
*
(
uint8_t
*
)(
val
+
i
*
tDataType
s
[
type
].
bytes
)
=
TSDB_DATA_BOOL_NULL
;
}
break
;
case
TSDB_DATA_TYPE_TINYINT
:
for
(
int32_t
i
=
0
;
i
<
numOfElems
;
++
i
)
{
*
(
uint8_t
*
)(
val
+
i
*
tDataType
Desc
[
type
].
nSize
)
=
TSDB_DATA_TINYINT_NULL
;
*
(
uint8_t
*
)(
val
+
i
*
tDataType
s
[
type
].
bytes
)
=
TSDB_DATA_TINYINT_NULL
;
}
break
;
case
TSDB_DATA_TYPE_SMALLINT
:
for
(
int32_t
i
=
0
;
i
<
numOfElems
;
++
i
)
{
*
(
uint16_t
*
)(
val
+
i
*
tDataType
Desc
[
type
].
nSize
)
=
TSDB_DATA_SMALLINT_NULL
;
*
(
uint16_t
*
)(
val
+
i
*
tDataType
s
[
type
].
bytes
)
=
TSDB_DATA_SMALLINT_NULL
;
}
break
;
case
TSDB_DATA_TYPE_INT
:
for
(
int32_t
i
=
0
;
i
<
numOfElems
;
++
i
)
{
*
(
uint32_t
*
)(
val
+
i
*
tDataType
Desc
[
type
].
nSize
)
=
TSDB_DATA_INT_NULL
;
*
(
uint32_t
*
)(
val
+
i
*
tDataType
s
[
type
].
bytes
)
=
TSDB_DATA_INT_NULL
;
}
break
;
case
TSDB_DATA_TYPE_BIGINT
:
case
TSDB_DATA_TYPE_TIMESTAMP
:
for
(
int32_t
i
=
0
;
i
<
numOfElems
;
++
i
)
{
*
(
uint64_t
*
)(
val
+
i
*
tDataType
Desc
[
type
].
nSize
)
=
TSDB_DATA_BIGINT_NULL
;
*
(
uint64_t
*
)(
val
+
i
*
tDataType
s
[
type
].
bytes
)
=
TSDB_DATA_BIGINT_NULL
;
}
break
;
case
TSDB_DATA_TYPE_UTINYINT
:
for
(
int32_t
i
=
0
;
i
<
numOfElems
;
++
i
)
{
*
(
uint8_t
*
)(
val
+
i
*
tDataType
Desc
[
type
].
nSize
)
=
TSDB_DATA_UTINYINT_NULL
;
*
(
uint8_t
*
)(
val
+
i
*
tDataType
s
[
type
].
bytes
)
=
TSDB_DATA_UTINYINT_NULL
;
}
break
;
case
TSDB_DATA_TYPE_USMALLINT
:
for
(
int32_t
i
=
0
;
i
<
numOfElems
;
++
i
)
{
*
(
uint16_t
*
)(
val
+
i
*
tDataType
Desc
[
type
].
nSize
)
=
TSDB_DATA_USMALLINT_NULL
;
*
(
uint16_t
*
)(
val
+
i
*
tDataType
s
[
type
].
bytes
)
=
TSDB_DATA_USMALLINT_NULL
;
}
break
;
case
TSDB_DATA_TYPE_UINT
:
for
(
int32_t
i
=
0
;
i
<
numOfElems
;
++
i
)
{
*
(
uint32_t
*
)(
val
+
i
*
tDataType
Desc
[
type
].
nSize
)
=
TSDB_DATA_UINT_NULL
;
*
(
uint32_t
*
)(
val
+
i
*
tDataType
s
[
type
].
bytes
)
=
TSDB_DATA_UINT_NULL
;
}
break
;
case
TSDB_DATA_TYPE_UBIGINT
:
for
(
int32_t
i
=
0
;
i
<
numOfElems
;
++
i
)
{
*
(
uint64_t
*
)(
val
+
i
*
tDataType
Desc
[
type
].
nSize
)
=
TSDB_DATA_UBIGINT_NULL
;
*
(
uint64_t
*
)(
val
+
i
*
tDataType
s
[
type
].
bytes
)
=
TSDB_DATA_UBIGINT_NULL
;
}
break
;
case
TSDB_DATA_TYPE_FLOAT
:
for
(
int32_t
i
=
0
;
i
<
numOfElems
;
++
i
)
{
*
(
uint32_t
*
)(
val
+
i
*
tDataType
Desc
[
type
].
nSize
)
=
TSDB_DATA_FLOAT_NULL
;
*
(
uint32_t
*
)(
val
+
i
*
tDataType
s
[
type
].
bytes
)
=
TSDB_DATA_FLOAT_NULL
;
}
break
;
case
TSDB_DATA_TYPE_DOUBLE
:
for
(
int32_t
i
=
0
;
i
<
numOfElems
;
++
i
)
{
*
(
uint64_t
*
)(
val
+
i
*
tDataType
Desc
[
type
].
nSize
)
=
TSDB_DATA_DOUBLE_NULL
;
*
(
uint64_t
*
)(
val
+
i
*
tDataType
s
[
type
].
bytes
)
=
TSDB_DATA_DOUBLE_NULL
;
}
break
;
case
TSDB_DATA_TYPE_NCHAR
:
...
...
@@ -485,7 +485,7 @@ void setNullN(char *val, int32_t type, int32_t bytes, int32_t numOfElems) {
break
;
default:
{
for
(
int32_t
i
=
0
;
i
<
numOfElems
;
++
i
)
{
*
(
uint32_t
*
)(
val
+
i
*
tDataType
Desc
[
TSDB_DATA_TYPE_INT
].
nSize
)
=
TSDB_DATA_INT_NULL
;
*
(
uint32_t
*
)(
val
+
i
*
tDataType
s
[
TSDB_DATA_TYPE_INT
].
bytes
)
=
TSDB_DATA_INT_NULL
;
}
break
;
}
...
...
@@ -524,15 +524,18 @@ void assignVal(char *val, const char *src, int32_t len, int32_t type) {
switch
(
type
)
{
case
TSDB_DATA_TYPE_BOOL
:
case
TSDB_DATA_TYPE_TINYINT
:
case
TSDB_DATA_TYPE_UTINYINT
:
*
((
int8_t
*
)
val
)
=
GET_INT8_VAL
(
src
);
break
;
case
TSDB_DATA_TYPE_SMALLINT
:
case
TSDB_DATA_TYPE_USMALLINT
:
*
((
int16_t
*
)
val
)
=
GET_INT16_VAL
(
src
);
break
;
case
TSDB_DATA_TYPE_INT
:
{
case
TSDB_DATA_TYPE_INT
:
case
TSDB_DATA_TYPE_UINT
:
*
((
int32_t
*
)
val
)
=
GET_INT32_VAL
(
src
);
break
;
}
case
TSDB_DATA_TYPE_FLOAT
:
SET_FLOAT_VAL
(
val
,
GET_FLOAT_VAL
(
src
));
break
;
...
...
@@ -540,6 +543,7 @@ void assignVal(char *val, const char *src, int32_t len, int32_t type) {
SET_DOUBLE_VAL
(
val
,
GET_DOUBLE_VAL
(
src
));
break
;
case
TSDB_DATA_TYPE_BIGINT
:
case
TSDB_DATA_TYPE_UBIGINT
:
case
TSDB_DATA_TYPE_TIMESTAMP
:
*
((
int64_t
*
)
val
)
=
GET_INT64_VAL
(
src
);
break
;
...
...
src/common/src/tvariant.c
浏览文件 @
c1b456be
...
...
@@ -205,7 +205,7 @@ void tVariantAssign(tVariant *pDst, const tVariant *pSrc) {
}
if
(
pDst
->
nType
!=
TSDB_DATA_TYPE_ARRAY
)
{
pDst
->
nLen
=
tDataType
Desc
[
pDst
->
nType
].
nSize
;
pDst
->
nLen
=
tDataType
s
[
pDst
->
nType
].
bytes
;
}
}
...
...
@@ -425,7 +425,7 @@ static FORCE_INLINE int32_t convertToDouble(char *pStr, int32_t len, double *val
static
FORCE_INLINE
int32_t
convertToInteger
(
tVariant
*
pVariant
,
int64_t
*
result
,
int32_t
type
,
bool
issigned
,
bool
releaseVariantPtr
)
{
if
(
pVariant
->
nType
==
TSDB_DATA_TYPE_NULL
)
{
setNull
((
char
*
)
result
,
type
,
tDataType
Desc
[
type
].
nSize
);
setNull
((
char
*
)
result
,
type
,
tDataType
s
[
type
].
bytes
);
return
0
;
}
...
...
@@ -446,7 +446,7 @@ static FORCE_INLINE int32_t convertToInteger(tVariant *pVariant, int64_t *result
pVariant
->
nLen
=
0
;
}
setNull
((
char
*
)
result
,
type
,
tDataType
Desc
[
type
].
nSize
);
setNull
((
char
*
)
result
,
type
,
tDataType
s
[
type
].
bytes
);
return
0
;
}
...
...
@@ -496,7 +496,7 @@ static FORCE_INLINE int32_t convertToInteger(tVariant *pVariant, int64_t *result
free
(
pVariant
->
pz
);
pVariant
->
nLen
=
0
;
}
setNull
((
char
*
)
result
,
type
,
tDataType
Desc
[
type
].
nSize
);
setNull
((
char
*
)
result
,
type
,
tDataType
s
[
type
].
bytes
);
return
0
;
}
else
{
int64_t
val
=
wcstoll
(
pVariant
->
wpz
,
&
endPtr
,
10
);
...
...
src/dnode/src/dnodeShell.c
浏览文件 @
c1b456be
...
...
@@ -216,7 +216,7 @@ void *dnodeSendCfgTableToRecv(int32_t vgId, int32_t tid) {
int16_t
numOfTags
=
htons
(
pTable
->
numOfTags
);
int32_t
tableId
=
htonl
(
pTable
->
tid
);
uint64_t
uid
=
htobe64
(
pTable
->
uid
);
dInfo
(
"table:%s, numOfColumns:%d numOfTags:%d tid:%d uid:%"
PRIu64
,
pTable
->
table
Id
,
numOfColumns
,
numOfTags
,
tableId
,
uid
);
dInfo
(
"table:%s, numOfColumns:%d numOfTags:%d tid:%d uid:%"
PRIu64
,
pTable
->
table
Fname
,
numOfColumns
,
numOfTags
,
tableId
,
uid
);
return
rpcRsp
.
pCont
;
}
...
...
src/inc/taos.h
浏览文件 @
c1b456be
...
...
@@ -140,7 +140,7 @@ DLL_EXPORT int taos_errno(TAOS_RES *tres);
DLL_EXPORT
void
taos_query_a
(
TAOS
*
taos
,
const
char
*
sql
,
void
(
*
fp
)(
void
*
param
,
TAOS_RES
*
,
int
code
),
void
*
param
);
DLL_EXPORT
void
taos_fetch_rows_a
(
TAOS_RES
*
res
,
void
(
*
fp
)(
void
*
param
,
TAOS_RES
*
,
int
numOfRows
),
void
*
param
);
DLL_EXPORT
void
taos_fetch_row_a
(
TAOS_RES
*
res
,
void
(
*
fp
)(
void
*
param
,
TAOS_RES
*
,
TAOS_ROW
row
),
void
*
param
);
//
DLL_EXPORT void taos_fetch_row_a(TAOS_RES *res, void (*fp)(void *param, TAOS_RES *, TAOS_ROW row), void *param);
typedef
void
(
*
TAOS_SUBSCRIBE_CALLBACK
)(
TAOS_SUB
*
tsub
,
TAOS_RES
*
res
,
void
*
param
,
int
code
);
DLL_EXPORT
TAOS_SUB
*
taos_subscribe
(
TAOS
*
taos
,
int
restart
,
const
char
*
topic
,
const
char
*
sql
,
TAOS_SUBSCRIBE_CALLBACK
fp
,
void
*
param
,
int
interval
);
...
...
src/inc/taosdef.h
浏览文件 @
c1b456be
...
...
@@ -36,29 +36,6 @@ extern "C" {
#define TSWINDOW_INITIALIZER ((STimeWindow) {INT64_MIN, INT64_MAX})
#define TSKEY_INITIAL_VAL INT64_MIN
// ----------------- For variable data types such as TSDB_DATA_TYPE_BINARY and TSDB_DATA_TYPE_NCHAR
typedef
int32_t
VarDataOffsetT
;
typedef
int16_t
VarDataLenT
;
typedef
struct
tstr
{
VarDataLenT
len
;
char
data
[];
}
tstr
;
#define VARSTR_HEADER_SIZE sizeof(VarDataLenT)
#define varDataLen(v) ((VarDataLenT *)(v))[0]
#define varDataTLen(v) (sizeof(VarDataLenT) + varDataLen(v))
#define varDataVal(v) ((void *)((char *)v + VARSTR_HEADER_SIZE))
#define varDataCopy(dst, v) memcpy((dst), (void*) (v), varDataTLen(v))
#define varDataLenByData(v) (*(VarDataLenT *)(((char*)(v)) - VARSTR_HEADER_SIZE))
#define varDataSetLen(v, _len) (((VarDataLenT *)(v))[0] = (VarDataLenT) (_len))
#define IS_VAR_DATA_TYPE(t) (((t) == TSDB_DATA_TYPE_BINARY) || ((t) == TSDB_DATA_TYPE_NCHAR))
// this data type is internally used only in 'in' query to hold the values
#define TSDB_DATA_TYPE_ARRAY (TSDB_DATA_TYPE_NCHAR + 1)
// Bytes for each type.
extern
const
int32_t
TYPE_BYTES
[
15
];
...
...
@@ -164,70 +141,6 @@ do { \
#define SET_DOUBLE_PTR(x, y) { (*(double *)(x)) = (*(double *)(y)); }
#endif
typedef
struct
tDataTypeDescriptor
{
int16_t
nType
;
int16_t
nameLen
;
int32_t
nSize
;
char
*
aName
;
int
(
*
compFunc
)(
const
char
*
const
input
,
int
inputSize
,
const
int
nelements
,
char
*
const
output
,
int
outputSize
,
char
algorithm
,
char
*
const
buffer
,
int
bufferSize
);
int
(
*
decompFunc
)(
const
char
*
const
input
,
int
compressedSize
,
const
int
nelements
,
char
*
const
output
,
int
outputSize
,
char
algorithm
,
char
*
const
buffer
,
int
bufferSize
);
void
(
*
getStatisFunc
)(
const
void
*
pData
,
int32_t
numofrow
,
int64_t
*
min
,
int64_t
*
max
,
int64_t
*
sum
,
int16_t
*
minindex
,
int16_t
*
maxindex
,
int16_t
*
numofnull
);
}
tDataTypeDescriptor
;
extern
tDataTypeDescriptor
tDataTypeDesc
[
15
];
bool
isValidDataType
(
int32_t
type
);
static
FORCE_INLINE
bool
isNull
(
const
char
*
val
,
int32_t
type
)
{
switch
(
type
)
{
case
TSDB_DATA_TYPE_BOOL
:
return
*
(
uint8_t
*
)
val
==
TSDB_DATA_BOOL_NULL
;
case
TSDB_DATA_TYPE_TINYINT
:
return
*
(
uint8_t
*
)
val
==
TSDB_DATA_TINYINT_NULL
;
case
TSDB_DATA_TYPE_SMALLINT
:
return
*
(
uint16_t
*
)
val
==
TSDB_DATA_SMALLINT_NULL
;
case
TSDB_DATA_TYPE_INT
:
return
*
(
uint32_t
*
)
val
==
TSDB_DATA_INT_NULL
;
case
TSDB_DATA_TYPE_BIGINT
:
case
TSDB_DATA_TYPE_TIMESTAMP
:
return
*
(
uint64_t
*
)
val
==
TSDB_DATA_BIGINT_NULL
;
case
TSDB_DATA_TYPE_FLOAT
:
return
*
(
uint32_t
*
)
val
==
TSDB_DATA_FLOAT_NULL
;
case
TSDB_DATA_TYPE_DOUBLE
:
return
*
(
uint64_t
*
)
val
==
TSDB_DATA_DOUBLE_NULL
;
case
TSDB_DATA_TYPE_NCHAR
:
return
varDataLen
(
val
)
==
sizeof
(
int32_t
)
&&
*
(
uint32_t
*
)
varDataVal
(
val
)
==
TSDB_DATA_NCHAR_NULL
;
case
TSDB_DATA_TYPE_BINARY
:
return
varDataLen
(
val
)
==
sizeof
(
int8_t
)
&&
*
(
uint8_t
*
)
varDataVal
(
val
)
==
TSDB_DATA_BINARY_NULL
;
case
TSDB_DATA_TYPE_UTINYINT
:
return
*
(
uint8_t
*
)
val
==
TSDB_DATA_UTINYINT_NULL
;
case
TSDB_DATA_TYPE_USMALLINT
:
return
*
(
uint16_t
*
)
val
==
TSDB_DATA_USMALLINT_NULL
;
case
TSDB_DATA_TYPE_UINT
:
return
*
(
uint32_t
*
)
val
==
TSDB_DATA_UINT_NULL
;
case
TSDB_DATA_TYPE_UBIGINT
:
return
*
(
uint64_t
*
)
val
==
TSDB_DATA_UBIGINT_NULL
;
default:
return
false
;
};
}
void
setVardataNull
(
char
*
val
,
int32_t
type
);
void
setNull
(
char
*
val
,
int32_t
type
,
int32_t
bytes
);
void
setNullN
(
char
*
val
,
int32_t
type
,
int32_t
bytes
,
int32_t
numOfElems
);
void
*
getNullValue
(
int32_t
type
);
void
assignVal
(
char
*
val
,
const
char
*
src
,
int32_t
len
,
int32_t
type
);
void
tsDataSwap
(
void
*
pLeft
,
void
*
pRight
,
int32_t
type
,
int32_t
size
,
void
*
buf
);
int32_t
tStrToInteger
(
const
char
*
z
,
int16_t
type
,
int32_t
n
,
int64_t
*
value
,
bool
issigned
);
#define SET_DOUBLE_NULL(v) (*(uint64_t *)(v) = TSDB_DATA_DOUBLE_NULL)
// TODO: check if below is necessary
#define TSDB_RELATION_INVALID 0
#define TSDB_RELATION_LESS 1
...
...
@@ -270,7 +183,7 @@ int32_t tStrToInteger(const char* z, int16_t type, int32_t n, int64_t* value, bo
#define TSDB_MAX_SAVED_SQL_LEN TSDB_MAX_COLUMNS * 64
#define TSDB_MAX_SQL_LEN TSDB_PAYLOAD_SIZE
#define TSDB_MAX_SQL_SHOW_LEN 512
#define TSDB_MAX_ALLOWED_SQL_LEN (1*1024*1024
U
) // sql length should be less than 1mb
#define TSDB_MAX_ALLOWED_SQL_LEN (1*1024*1024
u
) // sql length should be less than 1mb
#define TSDB_APPNAME_LEN TSDB_UNI_LEN
...
...
@@ -399,8 +312,8 @@ int32_t tStrToInteger(const char* z, int16_t type, int32_t n, int64_t* value, bo
#define TSDB_MAX_RPC_THREADS 5
#define TSDB_QUERY_TYPE_NON_TYPE
0x00u // none type
#define TSDB_QUERY_TYPE_FREE_RESOURCE
0x01u // free qhandle at vnode
#define TSDB_QUERY_TYPE_NON_TYPE 0x00u // none type
#define TSDB_QUERY_TYPE_FREE_RESOURCE 0x01u // free qhandle at vnode
/*
* 1. ordinary sub query for select * from super_table
...
...
@@ -420,29 +333,29 @@ int32_t tStrToInteger(const char* z, int16_t type, int32_t n, int64_t* value, bo
#define TSDB_QUERY_TYPE_MULTITABLE_QUERY 0x200u
#define TSDB_QUERY_TYPE_STMT_INSERT 0x800u // stmt insert type
#define TSDB_QUERY_HAS_TYPE(x, _type) (((x) & (_type)) != 0)
#define TSDB_QUERY_SET_TYPE(x, _type) ((x) |= (_type))
#define TSDB_QUERY_CLEAR_TYPE(x, _type) ((x) &= (~_type))
#define TSDB_QUERY_RESET_TYPE(x) ((x) = TSDB_QUERY_TYPE_NON_TYPE)
#define TSDB_ORDER_ASC 1
#define TSDB_ORDER_DESC 2
#define TSDB_DEFAULT_CLUSTER_HASH_SIZE 1
#define TSDB_DEFAULT_MNODES_HASH_SIZE 5
#define TSDB_DEFAULT_DNODES_HASH_SIZE 10
#define TSDB_DEFAULT_ACCOUNTS_HASH_SIZE 10
#define TSDB_DEFAULT_USERS_HASH_SIZE 20
#define TSDB_DEFAULT_DBS_HASH_SIZE 100
#define TSDB_DEFAULT_VGROUPS_HASH_SIZE 100
#define TSDB_DEFAULT_STABLES_HASH_SIZE 100
#define TSDB_DEFAULT_CTABLES_HASH_SIZE 20000
#define TSDB_PORT_DNODESHELL 0
#define TSDB_PORT_DNODEDNODE 5
#define TSDB_PORT_SYNC 10
#define TSDB_PORT_HTTP 11
#define TSDB_PORT_ARBITRATOR 12
#define TSDB_QUERY_HAS_TYPE(x, _type)
(((x) & (_type)) != 0)
#define TSDB_QUERY_SET_TYPE(x, _type)
((x) |= (_type))
#define TSDB_QUERY_CLEAR_TYPE(x, _type)
((x) &= (~_type))
#define TSDB_QUERY_RESET_TYPE(x)
((x) = TSDB_QUERY_TYPE_NON_TYPE)
#define TSDB_ORDER_ASC
1
#define TSDB_ORDER_DESC
2
#define TSDB_DEFAULT_CLUSTER_HASH_SIZE
1
#define TSDB_DEFAULT_MNODES_HASH_SIZE
5
#define TSDB_DEFAULT_DNODES_HASH_SIZE
10
#define TSDB_DEFAULT_ACCOUNTS_HASH_SIZE
10
#define TSDB_DEFAULT_USERS_HASH_SIZE
20
#define TSDB_DEFAULT_DBS_HASH_SIZE
100
#define TSDB_DEFAULT_VGROUPS_HASH_SIZE
100
#define TSDB_DEFAULT_STABLES_HASH_SIZE
100
#define TSDB_DEFAULT_CTABLES_HASH_SIZE
20000
#define TSDB_PORT_DNODESHELL
0
#define TSDB_PORT_DNODEDNODE
5
#define TSDB_PORT_SYNC
10
#define TSDB_PORT_HTTP
11
#define TSDB_PORT_ARBITRATOR
12
#define TSDB_MAX_WAL_SIZE (1024*1024*3)
...
...
src/inc/taosmsg.h
浏览文件 @
c1b456be
...
...
@@ -153,30 +153,31 @@ enum _mgmt_table {
#define TSDB_ALTER_TABLE_DROP_COLUMN 6
#define TSDB_ALTER_TABLE_CHANGE_COLUMN 7
#define TSDB_FILL_NONE 0
#define TSDB_FILL_NULL 1
#define TSDB_FILL_SET_VALUE 2
#define TSDB_FILL_LINEAR 3
#define TSDB_FILL_PREV 4
#define TSDB_ALTER_USER_PASSWD 0x1
#define TSDB_FILL_NONE 0
#define TSDB_FILL_NULL 1
#define TSDB_FILL_SET_VALUE 2
#define TSDB_FILL_LINEAR 3
#define TSDB_FILL_PREV 4
#define TSDB_FILL_NEXT 5
#define TSDB_ALTER_USER_PASSWD 0x1
#define TSDB_ALTER_USER_PRIVILEGES 0x2
#define TSDB_KILL_MSG_LEN 30
#define TSDB_KILL_MSG_LEN
30
#define TSDB_VN_READ_ACCCESS ((char)0x1)
#define TSDB_VN_WRITE_ACCCESS ((char)0x2)
#define TSDB_VN_READ_ACCCESS
((char)0x1)
#define TSDB_VN_WRITE_ACCCESS
((char)0x2)
#define TSDB_VN_ALL_ACCCESS (TSDB_VN_READ_ACCCESS | TSDB_VN_WRITE_ACCCESS)
#define TSDB_COL_NORMAL 0x0u // the normal column of the table
#define TSDB_COL_TAG 0x1u // the tag column type
#define TSDB_COL_UDC 0x2u // the user specified normal string column, it is a dummy column
#define TSDB_COL_NULL 0x4u // the column filter NULL or not
#define TSDB_COL_NORMAL
0x0u // the normal column of the table
#define TSDB_COL_TAG
0x1u // the tag column type
#define TSDB_COL_UDC
0x2u // the user specified normal string column, it is a dummy column
#define TSDB_COL_NULL
0x4u // the column filter NULL or not
#define TSDB_COL_IS_TAG(f) (((f&(~(TSDB_COL_NULL)))&TSDB_COL_TAG) != 0)
#define TSDB_COL_IS_NORMAL_COL(f)
((f&(~(TSDB_COL_NULL))) == TSDB_COL_NORMAL)
#define TSDB_COL_IS_UD_COL(f) ((f&(~(TSDB_COL_NULL))) == TSDB_COL_UDC)
#define TSDB_COL_REQ_NULL(f) (((f)&TSDB_COL_NULL) != 0)
#define TSDB_COL_IS_TAG(f)
(((f&(~(TSDB_COL_NULL)))&TSDB_COL_TAG) != 0)
#define TSDB_COL_IS_NORMAL_COL(f) ((f&(~(TSDB_COL_NULL))) == TSDB_COL_NORMAL)
#define TSDB_COL_IS_UD_COL(f)
((f&(~(TSDB_COL_NULL))) == TSDB_COL_UDC)
#define TSDB_COL_REQ_NULL(f)
(((f)&TSDB_COL_NULL) != 0)
extern
char
*
taosMsg
[];
...
...
@@ -260,14 +261,14 @@ typedef struct {
uint64_t
uid
;
uint64_t
superTableUid
;
uint64_t
createdTime
;
char
table
Id
[
TSDB_TABLE_FNAME_LEN
];
char
s
uperTableId
[
TSDB_TABLE_FNAME_LEN
];
char
table
Fname
[
TSDB_TABLE_FNAME_LEN
];
char
s
tableFname
[
TSDB_TABLE_FNAME_LEN
];
char
data
[];
}
SMDCreateTableMsg
;
typedef
struct
{
int32_t
len
;
// one create table message
char
table
Id
[
TSDB_TABLE_FNAME_LEN
];
char
table
Fname
[
TSDB_TABLE_FNAME_LEN
];
char
db
[
TSDB_ACCT_ID_LEN
+
TSDB_DB_NAME_LEN
];
int8_t
igExists
;
int8_t
getMeta
;
...
...
@@ -284,12 +285,12 @@ typedef struct {
}
SCMCreateTableMsg
;
typedef
struct
{
char
table
Id
[
TSDB_TABLE_FNAME_LEN
];
char
table
Fname
[
TSDB_TABLE_FNAME_LEN
];
int8_t
igNotExists
;
}
SCMDropTableMsg
;
typedef
struct
{
char
table
Id
[
TSDB_TABLE_FNAME_LEN
];
char
table
Fname
[
TSDB_TABLE_FNAME_LEN
];
char
db
[
TSDB_ACCT_ID_LEN
+
TSDB_DB_NAME_LEN
];
int16_t
type
;
/* operation type */
int16_t
numOfCols
;
/* number of schema */
...
...
@@ -369,14 +370,14 @@ typedef struct {
int32_t
vgId
;
int32_t
tid
;
uint64_t
uid
;
char
table
Id
[
TSDB_TABLE_FNAME_LEN
];
char
table
Fname
[
TSDB_TABLE_FNAME_LEN
];
}
SMDDropTableMsg
;
typedef
struct
{
int32_t
contLen
;
int32_t
vgId
;
uint64_t
uid
;
char
table
Id
[
TSDB_TABLE_FNAME_LEN
];
char
table
Fname
[
TSDB_TABLE_FNAME_LEN
];
}
SDropSTableMsg
;
typedef
struct
{
...
...
@@ -688,7 +689,7 @@ typedef struct {
}
SCreateVnodeMsg
,
SAlterVnodeMsg
;
typedef
struct
{
char
table
Id
[
TSDB_TABLE_FNAME_LEN
];
char
table
Fname
[
TSDB_TABLE_FNAME_LEN
];
int16_t
createFlag
;
char
tags
[];
}
STableInfoMsg
;
...
...
@@ -726,7 +727,7 @@ typedef struct {
typedef
struct
STableMetaMsg
{
int32_t
contLen
;
char
table
Id
[
TSDB_TABLE_FNAME_LEN
];
// table id
char
table
Fname
[
TSDB_TABLE_FNAME_LEN
];
// table id
uint8_t
numOfTags
;
uint8_t
precision
;
uint8_t
tableType
;
...
...
@@ -847,7 +848,7 @@ typedef struct {
uint64_t
uid
;
uint64_t
stime
;
// stream starting time
int32_t
status
;
char
table
Id
[
TSDB_TABLE_FNAME_LEN
];
char
table
Fname
[
TSDB_TABLE_FNAME_LEN
];
}
SAlterStreamMsg
;
typedef
struct
{
...
...
src/inc/ttype.h
浏览文件 @
c1b456be
...
...
@@ -7,6 +7,28 @@ extern "C" {
#include "taosdef.h"
// ----------------- For variable data types such as TSDB_DATA_TYPE_BINARY and TSDB_DATA_TYPE_NCHAR
typedef
int32_t
VarDataOffsetT
;
typedef
int16_t
VarDataLenT
;
typedef
struct
tstr
{
VarDataLenT
len
;
char
data
[];
}
tstr
;
#define VARSTR_HEADER_SIZE sizeof(VarDataLenT)
#define varDataLen(v) ((VarDataLenT *)(v))[0]
#define varDataTLen(v) (sizeof(VarDataLenT) + varDataLen(v))
#define varDataVal(v) ((void *)((char *)v + VARSTR_HEADER_SIZE))
#define varDataCopy(dst, v) memcpy((dst), (void*) (v), varDataTLen(v))
#define varDataLenByData(v) (*(VarDataLenT *)(((char*)(v)) - VARSTR_HEADER_SIZE))
#define varDataSetLen(v, _len) (((VarDataLenT *)(v))[0] = (VarDataLenT) (_len))
#define IS_VAR_DATA_TYPE(t) (((t) == TSDB_DATA_TYPE_BINARY) || ((t) == TSDB_DATA_TYPE_NCHAR))
// this data type is internally used only in 'in' query to hold the values
#define TSDB_DATA_TYPE_ARRAY (TSDB_DATA_TYPE_NCHAR + 1)
#define GET_TYPED_DATA(_v, _finalType, _type, _data) \
do { \
switch (_type) { \
...
...
@@ -59,6 +81,70 @@ extern "C" {
#define IS_VALID_UINT(_t) ((_t) >= 0 && (_t) < UINT32_MAX)
#define IS_VALID_UBIGINT(_t) ((_t) >= 0 && (_t) < UINT64_MAX)
static
FORCE_INLINE
bool
isNull
(
const
char
*
val
,
int32_t
type
)
{
switch
(
type
)
{
case
TSDB_DATA_TYPE_BOOL
:
return
*
(
uint8_t
*
)
val
==
TSDB_DATA_BOOL_NULL
;
case
TSDB_DATA_TYPE_TINYINT
:
return
*
(
uint8_t
*
)
val
==
TSDB_DATA_TINYINT_NULL
;
case
TSDB_DATA_TYPE_SMALLINT
:
return
*
(
uint16_t
*
)
val
==
TSDB_DATA_SMALLINT_NULL
;
case
TSDB_DATA_TYPE_INT
:
return
*
(
uint32_t
*
)
val
==
TSDB_DATA_INT_NULL
;
case
TSDB_DATA_TYPE_BIGINT
:
case
TSDB_DATA_TYPE_TIMESTAMP
:
return
*
(
uint64_t
*
)
val
==
TSDB_DATA_BIGINT_NULL
;
case
TSDB_DATA_TYPE_FLOAT
:
return
*
(
uint32_t
*
)
val
==
TSDB_DATA_FLOAT_NULL
;
case
TSDB_DATA_TYPE_DOUBLE
:
return
*
(
uint64_t
*
)
val
==
TSDB_DATA_DOUBLE_NULL
;
case
TSDB_DATA_TYPE_NCHAR
:
return
varDataLen
(
val
)
==
sizeof
(
int32_t
)
&&
*
(
uint32_t
*
)
varDataVal
(
val
)
==
TSDB_DATA_NCHAR_NULL
;
case
TSDB_DATA_TYPE_BINARY
:
return
varDataLen
(
val
)
==
sizeof
(
int8_t
)
&&
*
(
uint8_t
*
)
varDataVal
(
val
)
==
TSDB_DATA_BINARY_NULL
;
case
TSDB_DATA_TYPE_UTINYINT
:
return
*
(
uint8_t
*
)
val
==
TSDB_DATA_UTINYINT_NULL
;
case
TSDB_DATA_TYPE_USMALLINT
:
return
*
(
uint16_t
*
)
val
==
TSDB_DATA_USMALLINT_NULL
;
case
TSDB_DATA_TYPE_UINT
:
return
*
(
uint32_t
*
)
val
==
TSDB_DATA_UINT_NULL
;
case
TSDB_DATA_TYPE_UBIGINT
:
return
*
(
uint64_t
*
)
val
==
TSDB_DATA_UBIGINT_NULL
;
default:
return
false
;
};
}
typedef
struct
tDataTypeDescriptor
{
int16_t
type
;
int16_t
nameLen
;
int32_t
bytes
;
char
*
name
;
int
(
*
compFunc
)(
const
char
*
const
input
,
int
inputSize
,
const
int
nelements
,
char
*
const
output
,
int
outputSize
,
char
algorithm
,
char
*
const
buffer
,
int
bufferSize
);
int
(
*
decompFunc
)(
const
char
*
const
input
,
int
compressedSize
,
const
int
nelements
,
char
*
const
output
,
int
outputSize
,
char
algorithm
,
char
*
const
buffer
,
int
bufferSize
);
void
(
*
statisFunc
)(
const
void
*
pData
,
int32_t
numofrow
,
int64_t
*
min
,
int64_t
*
max
,
int64_t
*
sum
,
int16_t
*
minindex
,
int16_t
*
maxindex
,
int16_t
*
numofnull
);
}
tDataTypeDescriptor
;
extern
tDataTypeDescriptor
tDataTypes
[
15
];
bool
isValidDataType
(
int32_t
type
);
void
setVardataNull
(
char
*
val
,
int32_t
type
);
void
setNull
(
char
*
val
,
int32_t
type
,
int32_t
bytes
);
void
setNullN
(
char
*
val
,
int32_t
type
,
int32_t
bytes
,
int32_t
numOfElems
);
void
*
getNullValue
(
int32_t
type
);
void
assignVal
(
char
*
val
,
const
char
*
src
,
int32_t
len
,
int32_t
type
);
void
tsDataSwap
(
void
*
pLeft
,
void
*
pRight
,
int32_t
type
,
int32_t
size
,
void
*
buf
);
int32_t
tStrToInteger
(
const
char
*
z
,
int16_t
type
,
int32_t
n
,
int64_t
*
value
,
bool
issigned
);
#define SET_DOUBLE_NULL(v) (*(uint64_t *)(v) = TSDB_DATA_DOUBLE_NULL)
#ifdef __cplusplus
}
#endif
...
...
src/mnode/src/mnodeCluster.c
浏览文件 @
c1b456be
...
...
@@ -195,7 +195,7 @@ static int32_t mnodeGetClusterMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *
cols
++
;
pMeta
->
numOfColumns
=
htons
(
cols
);
strcpy
(
pMeta
->
table
Id
,
"show cluster"
);
strcpy
(
pMeta
->
table
Fname
,
"show cluster"
);
pShow
->
numOfColumns
=
cols
;
pShow
->
offset
[
0
]
=
0
;
...
...
src/mnode/src/mnodeTable.c
浏览文件 @
c1b456be
此差异已折叠。
点击以展开。
src/mnode/src/mnodeUser.c
浏览文件 @
c1b456be
...
...
@@ -337,7 +337,7 @@ static int32_t mnodeGetUserMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pCo
cols
++
;
pMeta
->
numOfColumns
=
htons
(
cols
);
strcpy
(
pMeta
->
table
Id
,
"show users"
);
strcpy
(
pMeta
->
table
Fname
,
"show users"
);
pShow
->
numOfColumns
=
cols
;
pShow
->
offset
[
0
]
=
0
;
...
...
src/query/inc/qFill.h
浏览文件 @
c1b456be
...
...
@@ -82,9 +82,9 @@ void taosFillCopyInputDataFromFilePage(SFillInfo* pFillInfo, const tFilePage** p
void
taosFillCopyInputDataFromOneFilePage
(
SFillInfo
*
pFillInfo
,
const
tFilePage
*
pInput
);
int64_t
getNumOfResWithFill
(
SFillInfo
*
pFillInfo
,
int64_t
ekey
,
int32_t
maxNumOfRows
);
bool
taosFillHasMoreResults
(
SFillInfo
*
pFillInfo
);
int
32_t
taosNumOfRemainRows
(
SFillInfo
*
pFillInfo
);
int
64_t
getNumOfResultsAfterFillGap
(
SFillInfo
*
pFillInfo
,
int64_t
ekey
,
int32_t
maxNumOfRows
);
int32_t
taosGetLinearInterpolationVal
(
int32_t
type
,
SPoint
*
point1
,
SPoint
*
point2
,
SPoint
*
point
);
...
...
src/query/src/qAggMain.c
浏览文件 @
c1b456be
...
...
@@ -1901,7 +1901,7 @@ static void valuePairAssign(tValuePair *dst, int16_t type, const char *val, int6
static
void
do_top_function_add
(
STopBotInfo
*
pInfo
,
int32_t
maxLen
,
void
*
pData
,
int64_t
ts
,
uint16_t
type
,
SExtTagsInfo
*
pTagInfo
,
char
*
pTags
,
int16_t
stage
)
{
tVariant
val
=
{
0
};
tVariantCreateFromBinary
(
&
val
,
pData
,
tDataType
Desc
[
type
].
nSize
,
type
);
tVariantCreateFromBinary
(
&
val
,
pData
,
tDataType
s
[
type
].
bytes
,
type
);
tValuePair
**
pList
=
pInfo
->
res
;
assert
(
pList
!=
NULL
);
...
...
@@ -1958,7 +1958,7 @@ static void do_top_function_add(STopBotInfo *pInfo, int32_t maxLen, void *pData,
static
void
do_bottom_function_add
(
STopBotInfo
*
pInfo
,
int32_t
maxLen
,
void
*
pData
,
int64_t
ts
,
uint16_t
type
,
SExtTagsInfo
*
pTagInfo
,
char
*
pTags
,
int16_t
stage
)
{
tVariant
val
=
{
0
};
tVariantCreateFromBinary
(
&
val
,
pData
,
tDataType
Desc
[
type
].
nSize
,
type
);
tVariantCreateFromBinary
(
&
val
,
pData
,
tDataType
s
[
type
].
bytes
,
type
);
tValuePair
**
pList
=
pInfo
->
res
;
assert
(
pList
!=
NULL
);
...
...
src/query/src/qArithmeticOperator.c
浏览文件 @
c1b456be
此差异已折叠。
点击以展开。
src/query/src/qExecutor.c
浏览文件 @
c1b456be
...
...
@@ -4180,7 +4180,7 @@ static void stableApplyFunctionsOnBlock(SQueryRuntimeEnv *pRuntimeEnv, SDataBloc
}
}
bool
queryHasRemainResForTableQuery
(
SQueryRuntimeEnv
*
pRuntimeEnv
)
{
bool
hasNotReturnedResults
(
SQueryRuntimeEnv
*
pRuntimeEnv
)
{
SQuery
*
pQuery
=
pRuntimeEnv
->
pQuery
;
SFillInfo
*
pFillInfo
=
pRuntimeEnv
->
pFillInfo
;
...
...
@@ -4190,8 +4190,7 @@ bool queryHasRemainResForTableQuery(SQueryRuntimeEnv* pRuntimeEnv) {
if
(
pQuery
->
fillType
!=
TSDB_FILL_NONE
&&
!
isPointInterpoQuery
(
pQuery
))
{
// There are results not returned to client yet, so filling applied to the remain result is required firstly.
int32_t
remain
=
taosNumOfRemainRows
(
pFillInfo
);
if
(
remain
>
0
)
{
if
(
taosFillHasMoreResults
(
pFillInfo
))
{
return
true
;
}
...
...
@@ -4205,7 +4204,7 @@ bool queryHasRemainResForTableQuery(SQueryRuntimeEnv* pRuntimeEnv) {
* first result row in the actual result set will fill nothing.
*/
if
(
Q_STATUS_EQUAL
(
pQuery
->
status
,
QUERY_COMPLETED
))
{
int32_t
numOfTotal
=
(
int32_t
)
getNumOfRes
WithFill
(
pFillInfo
,
pQuery
->
window
.
ekey
,
(
int32_t
)
pQuery
->
rec
.
capacity
);
int32_t
numOfTotal
=
(
int32_t
)
getNumOfRes
ultsAfterFillGap
(
pFillInfo
,
pQuery
->
window
.
ekey
,
(
int32_t
)
pQuery
->
rec
.
capacity
);
return
numOfTotal
>
0
;
}
...
...
@@ -4273,7 +4272,7 @@ static void doCopyQueryResultToMsg(SQInfo *pQInfo, int32_t numOfRows, char *data
setQueryStatus
(
pQuery
,
QUERY_OVER
);
}
}
else
{
if
(
!
queryHasRemainResForTableQuery
(
&
pQInfo
->
runtimeEnv
))
{
if
(
!
hasNotReturnedResults
(
&
pQInfo
->
runtimeEnv
))
{
setQueryStatus
(
pQuery
,
QUERY_OVER
);
}
}
...
...
@@ -4300,7 +4299,6 @@ int32_t doFillGapsInResults(SQueryRuntimeEnv* pRuntimeEnv, tFilePage **pDst, int
pQInfo
,
pFillInfo
->
numOfRows
,
ret
,
pQuery
->
limit
.
offset
,
ret
-
pQuery
->
limit
.
offset
,
0
);
ret
-=
(
int32_t
)
pQuery
->
limit
.
offset
;
// todo !!!!there exactly number of interpo is not valid.
for
(
int32_t
i
=
0
;
i
<
pQuery
->
numOfOutput
;
++
i
)
{
memmove
(
pDst
[
i
]
->
data
,
pDst
[
i
]
->
data
+
pQuery
->
pExpr1
[
i
].
bytes
*
pQuery
->
limit
.
offset
,
ret
*
pQuery
->
pExpr1
[
i
].
bytes
);
...
...
@@ -4318,7 +4316,7 @@ int32_t doFillGapsInResults(SQueryRuntimeEnv* pRuntimeEnv, tFilePage **pDst, int
ret
=
0
;
}
if
(
!
queryHasRemainResForTableQuery
(
pRuntimeEnv
))
{
if
(
!
hasNotReturnedResults
(
pRuntimeEnv
))
{
return
ret
;
}
}
...
...
@@ -5778,7 +5776,7 @@ static void tableQueryImpl(SQInfo *pQInfo) {
SQueryRuntimeEnv
*
pRuntimeEnv
=
&
pQInfo
->
runtimeEnv
;
SQuery
*
pQuery
=
pRuntimeEnv
->
pQuery
;
if
(
queryHasRemainResForTableQuery
(
pRuntimeEnv
))
{
if
(
hasNotReturnedResults
(
pRuntimeEnv
))
{
if
(
pQuery
->
fillType
!=
TSDB_FILL_NONE
)
{
/*
* There are remain results that are not returned due to result interpolation
...
...
@@ -6318,7 +6316,7 @@ static int32_t createQueryFuncExprFromMsg(SQueryTableMsg *pQueryMsg, int32_t num
}
type
=
TSDB_DATA_TYPE_DOUBLE
;
bytes
=
tDataType
Desc
[
type
].
nSize
;
bytes
=
tDataType
s
[
type
].
bytes
;
}
else
if
(
pExprs
[
i
].
base
.
colInfo
.
colId
==
TSDB_TBNAME_COLUMN_INDEX
&&
pExprs
[
i
].
base
.
functionId
==
TSDB_FUNC_TAGPRJ
)
{
// parse the normal column
SSchema
s
=
tGetTableNameColumnSchema
();
type
=
s
.
type
;
...
...
src/query/src/qFill.c
浏览文件 @
c1b456be
...
...
@@ -25,237 +25,8 @@
#include "queryLog.h"
#define FILL_IS_ASC_FILL(_f) ((_f)->order == TSDB_ORDER_ASC)
// there are no duplicated tags in the SFillTagColInfo list
static
int32_t
setTagColumnInfo
(
SFillInfo
*
pFillInfo
,
int32_t
numOfCols
,
int32_t
capacity
)
{
int32_t
rowsize
=
0
;
int32_t
k
=
0
;
for
(
int32_t
i
=
0
;
i
<
numOfCols
;
++
i
)
{
SFillColInfo
*
pColInfo
=
&
pFillInfo
->
pFillCol
[
i
];
pFillInfo
->
pData
[
i
]
=
calloc
(
1
,
pColInfo
->
col
.
bytes
*
capacity
);
if
(
TSDB_COL_IS_TAG
(
pColInfo
->
flag
))
{
bool
exists
=
false
;
int32_t
index
=
-
1
;
for
(
int32_t
j
=
0
;
j
<
k
;
++
j
)
{
if
(
pFillInfo
->
pTags
[
j
].
col
.
colId
==
pColInfo
->
col
.
colId
)
{
exists
=
true
;
index
=
j
;
break
;
}
}
if
(
!
exists
)
{
SSchema
*
pSchema
=
&
pFillInfo
->
pTags
[
k
].
col
;
pSchema
->
colId
=
pColInfo
->
col
.
colId
;
pSchema
->
type
=
pColInfo
->
col
.
type
;
pSchema
->
bytes
=
pColInfo
->
col
.
bytes
;
pFillInfo
->
pTags
[
k
].
tagVal
=
calloc
(
1
,
pColInfo
->
col
.
bytes
);
pColInfo
->
tagIndex
=
k
;
k
+=
1
;
}
else
{
pColInfo
->
tagIndex
=
index
;
}
}
rowsize
+=
pColInfo
->
col
.
bytes
;
}
assert
(
k
<=
pFillInfo
->
numOfTags
);
return
rowsize
;
}
SFillInfo
*
taosInitFillInfo
(
int32_t
order
,
TSKEY
skey
,
int32_t
numOfTags
,
int32_t
capacity
,
int32_t
numOfCols
,
int64_t
slidingTime
,
int8_t
slidingUnit
,
int8_t
precision
,
int32_t
fillType
,
SFillColInfo
*
pCol
,
void
*
handle
)
{
if
(
fillType
==
TSDB_FILL_NONE
)
{
return
NULL
;
}
SFillInfo
*
pFillInfo
=
calloc
(
1
,
sizeof
(
SFillInfo
));
taosResetFillInfo
(
pFillInfo
,
skey
);
pFillInfo
->
order
=
order
;
pFillInfo
->
type
=
fillType
;
pFillInfo
->
pFillCol
=
pCol
;
pFillInfo
->
numOfTags
=
numOfTags
;
pFillInfo
->
numOfCols
=
numOfCols
;
pFillInfo
->
precision
=
precision
;
pFillInfo
->
alloc
=
capacity
;
pFillInfo
->
handle
=
handle
;
pFillInfo
->
interval
.
interval
=
slidingTime
;
pFillInfo
->
interval
.
intervalUnit
=
slidingUnit
;
pFillInfo
->
interval
.
sliding
=
slidingTime
;
pFillInfo
->
interval
.
slidingUnit
=
slidingUnit
;
pFillInfo
->
pData
=
malloc
(
POINTER_BYTES
*
numOfCols
);
if
(
numOfTags
>
0
)
{
pFillInfo
->
pTags
=
calloc
(
pFillInfo
->
numOfTags
,
sizeof
(
SFillTagColInfo
));
for
(
int32_t
i
=
0
;
i
<
numOfTags
;
++
i
)
{
pFillInfo
->
pTags
[
i
].
col
.
colId
=
-
2
;
// TODO
}
}
pFillInfo
->
rowSize
=
setTagColumnInfo
(
pFillInfo
,
pFillInfo
->
numOfCols
,
pFillInfo
->
alloc
);
assert
(
pFillInfo
->
rowSize
>
0
);
return
pFillInfo
;
}
void
taosResetFillInfo
(
SFillInfo
*
pFillInfo
,
TSKEY
startTimestamp
)
{
pFillInfo
->
start
=
startTimestamp
;
pFillInfo
->
currentKey
=
startTimestamp
;
pFillInfo
->
index
=
-
1
;
pFillInfo
->
numOfRows
=
0
;
pFillInfo
->
numOfCurrent
=
0
;
pFillInfo
->
numOfTotal
=
0
;
}
void
*
taosDestroyFillInfo
(
SFillInfo
*
pFillInfo
)
{
if
(
pFillInfo
==
NULL
)
{
return
NULL
;
}
tfree
(
pFillInfo
->
prevValues
);
tfree
(
pFillInfo
->
nextValues
);
tfree
(
pFillInfo
->
pTags
);
for
(
int32_t
i
=
0
;
i
<
pFillInfo
->
numOfCols
;
++
i
)
{
tfree
(
pFillInfo
->
pData
[
i
]);
}
tfree
(
pFillInfo
->
pData
);
tfree
(
pFillInfo
->
pFillCol
);
tfree
(
pFillInfo
);
return
NULL
;
}
void
taosFillSetStartInfo
(
SFillInfo
*
pFillInfo
,
int32_t
numOfRows
,
TSKEY
endKey
)
{
if
(
pFillInfo
->
type
==
TSDB_FILL_NONE
)
{
return
;
}
pFillInfo
->
end
=
endKey
;
if
(
!
FILL_IS_ASC_FILL
(
pFillInfo
))
{
pFillInfo
->
end
=
taosTimeTruncate
(
endKey
,
&
pFillInfo
->
interval
,
pFillInfo
->
precision
);
}
pFillInfo
->
index
=
0
;
pFillInfo
->
numOfRows
=
numOfRows
;
// ensure the space
if
(
pFillInfo
->
alloc
<
numOfRows
)
{
for
(
int32_t
i
=
0
;
i
<
pFillInfo
->
numOfCols
;
++
i
)
{
char
*
tmp
=
realloc
(
pFillInfo
->
pData
[
i
],
numOfRows
*
pFillInfo
->
pFillCol
[
i
].
col
.
bytes
);
assert
(
tmp
!=
NULL
);
// todo handle error
memset
(
tmp
,
0
,
numOfRows
*
pFillInfo
->
pFillCol
[
i
].
col
.
bytes
);
pFillInfo
->
pData
[
i
]
=
tmp
;
}
}
}
// copy the data into source data buffer
void
taosFillCopyInputDataFromFilePage
(
SFillInfo
*
pFillInfo
,
const
tFilePage
**
pInput
)
{
for
(
int32_t
i
=
0
;
i
<
pFillInfo
->
numOfCols
;
++
i
)
{
memcpy
(
pFillInfo
->
pData
[
i
],
pInput
[
i
]
->
data
,
pFillInfo
->
numOfRows
*
pFillInfo
->
pFillCol
[
i
].
col
.
bytes
);
}
}
void
taosFillCopyInputDataFromOneFilePage
(
SFillInfo
*
pFillInfo
,
const
tFilePage
*
pInput
)
{
assert
(
pFillInfo
->
numOfRows
==
pInput
->
num
);
for
(
int32_t
i
=
0
;
i
<
pFillInfo
->
numOfCols
;
++
i
)
{
SFillColInfo
*
pCol
=
&
pFillInfo
->
pFillCol
[
i
];
const
char
*
data
=
pInput
->
data
+
pCol
->
col
.
offset
*
pInput
->
num
;
memcpy
(
pFillInfo
->
pData
[
i
],
data
,
(
size_t
)(
pInput
->
num
*
pCol
->
col
.
bytes
));
if
(
TSDB_COL_IS_TAG
(
pCol
->
flag
))
{
// copy the tag value to tag value buffer
SFillTagColInfo
*
pTag
=
&
pFillInfo
->
pTags
[
pCol
->
tagIndex
];
assert
(
pTag
->
col
.
colId
==
pCol
->
col
.
colId
);
memcpy
(
pTag
->
tagVal
,
data
,
pCol
->
col
.
bytes
);
}
}
}
int64_t
getNumOfResWithFill
(
SFillInfo
*
pFillInfo
,
TSKEY
ekey
,
int32_t
maxNumOfRows
)
{
int64_t
*
tsList
=
(
int64_t
*
)
pFillInfo
->
pData
[
0
];
int32_t
numOfRows
=
taosNumOfRemainRows
(
pFillInfo
);
TSKEY
ekey1
=
ekey
;
if
(
!
FILL_IS_ASC_FILL
(
pFillInfo
))
{
pFillInfo
->
end
=
taosTimeTruncate
(
ekey
,
&
pFillInfo
->
interval
,
pFillInfo
->
precision
);
}
int64_t
numOfRes
=
-
1
;
if
(
numOfRows
>
0
)
{
// still fill gap within current data block, not generating data after the result set.
TSKEY
lastKey
=
tsList
[
pFillInfo
->
numOfRows
-
1
];
numOfRes
=
taosTimeCountInterval
(
lastKey
,
pFillInfo
->
currentKey
,
pFillInfo
->
interval
.
sliding
,
pFillInfo
->
interval
.
slidingUnit
,
pFillInfo
->
precision
);
numOfRes
+=
1
;
assert
(
numOfRes
>=
numOfRows
);
}
else
{
// reach the end of data
if
((
ekey1
<
pFillInfo
->
currentKey
&&
FILL_IS_ASC_FILL
(
pFillInfo
))
||
(
ekey1
>
pFillInfo
->
currentKey
&&
!
FILL_IS_ASC_FILL
(
pFillInfo
)))
{
return
0
;
}
numOfRes
=
taosTimeCountInterval
(
ekey1
,
pFillInfo
->
currentKey
,
pFillInfo
->
interval
.
sliding
,
pFillInfo
->
interval
.
slidingUnit
,
pFillInfo
->
precision
);
numOfRes
+=
1
;
}
return
(
numOfRes
>
maxNumOfRows
)
?
maxNumOfRows
:
numOfRes
;
}
int32_t
taosNumOfRemainRows
(
SFillInfo
*
pFillInfo
)
{
if
(
pFillInfo
->
numOfRows
==
0
||
(
pFillInfo
->
numOfRows
>
0
&&
pFillInfo
->
index
>=
pFillInfo
->
numOfRows
))
{
return
0
;
}
return
pFillInfo
->
numOfRows
-
pFillInfo
->
index
;
}
#define DO_INTERPOLATION(_v1, _v2, _k1, _k2, _k) ((_v1) + ((_v2) - (_v1)) * (((double)(_k)) - ((double)(_k1))) / (((double)(_k2)) - ((double)(_k1))))
int32_t
taosGetLinearInterpolationVal
(
int32_t
type
,
SPoint
*
point1
,
SPoint
*
point2
,
SPoint
*
point
)
{
double
v1
=
-
1
;
double
v2
=
-
1
;
GET_TYPED_DATA
(
v1
,
double
,
type
,
point1
->
val
);
GET_TYPED_DATA
(
v2
,
double
,
type
,
point2
->
val
);
double
r
=
DO_INTERPOLATION
(
v1
,
v2
,
point1
->
key
,
point2
->
key
,
point
->
key
);
switch
(
type
)
{
case
TSDB_DATA_TYPE_TINYINT
:
*
(
int8_t
*
)
point
->
val
=
(
int8_t
)
r
;
break
;
case
TSDB_DATA_TYPE_SMALLINT
:
*
(
int16_t
*
)
point
->
val
=
(
int16_t
)
r
;
break
;
case
TSDB_DATA_TYPE_INT
:
*
(
int32_t
*
)
point
->
val
=
(
int32_t
)
r
;
break
;
case
TSDB_DATA_TYPE_BIGINT
:
*
(
int64_t
*
)
point
->
val
=
(
int64_t
)
r
;
break
;
case
TSDB_DATA_TYPE_DOUBLE
:
*
(
double
*
)
point
->
val
=
(
double
)
r
;
break
;
case
TSDB_DATA_TYPE_FLOAT
:
*
(
float
*
)
point
->
val
=
(
float
)
r
;
break
;
default:
assert
(
0
);
}
return
TSDB_CODE_SUCCESS
;
}
static
void
setTagsValue
(
SFillInfo
*
pFillInfo
,
tFilePage
**
data
,
int32_t
genRows
)
{
for
(
int32_t
j
=
0
;
j
<
pFillInfo
->
numOfCols
;
++
j
)
{
SFillColInfo
*
pCol
=
&
pFillInfo
->
pFillCol
[
j
];
...
...
@@ -298,7 +69,23 @@ static void doFillOneRowResult(SFillInfo* pFillInfo, tFilePage** data, char** sr
// set the other values
if
(
pFillInfo
->
type
==
TSDB_FILL_PREV
)
{
char
*
p
=
FILL_IS_ASC_FILL
(
pFillInfo
)
?
prev
:
next
;
if
(
p
!=
NULL
)
{
for
(
int32_t
i
=
1
;
i
<
pFillInfo
->
numOfCols
;
++
i
)
{
SFillColInfo
*
pCol
=
&
pFillInfo
->
pFillCol
[
i
];
if
(
TSDB_COL_IS_TAG
(
pCol
->
flag
))
{
continue
;
}
char
*
output
=
elePtrAt
(
data
[
i
]
->
data
,
pCol
->
col
.
bytes
,
index
);
assignVal
(
output
,
p
+
pCol
->
col
.
offset
,
pCol
->
col
.
bytes
,
pCol
->
col
.
type
);
}
}
else
{
// no prev value yet, set the value for NULL
setNullValueForRow
(
pFillInfo
,
data
,
pFillInfo
->
numOfCols
,
index
);
}
}
else
if
(
pFillInfo
->
type
==
TSDB_FILL_NEXT
)
{
char
*
p
=
FILL_IS_ASC_FILL
(
pFillInfo
)
?
next
:
prev
;
if
(
p
!=
NULL
)
{
for
(
int32_t
i
=
1
;
i
<
pFillInfo
->
numOfCols
;
++
i
)
{
SFillColInfo
*
pCol
=
&
pFillInfo
->
pFillCol
[
i
];
...
...
@@ -323,7 +110,7 @@ static void doFillOneRowResult(SFillInfo* pFillInfo, tFilePage** data, char** sr
int16_t
type
=
pCol
->
col
.
type
;
int16_t
bytes
=
pCol
->
col
.
bytes
;
char
*
val1
=
elePtrAt
(
data
[
i
]
->
data
,
pCol
->
col
.
bytes
,
index
);
if
(
type
==
TSDB_DATA_TYPE_BINARY
||
type
==
TSDB_DATA_TYPE_NCHAR
||
type
==
TSDB_DATA_TYPE_BOOL
)
{
setNull
(
val1
,
pCol
->
col
.
type
,
bytes
);
...
...
@@ -359,7 +146,7 @@ static void initBeforeAfterDataBuf(SFillInfo* pFillInfo, char** next) {
if
(
*
next
!=
NULL
)
{
return
;
}
*
next
=
calloc
(
1
,
pFillInfo
->
rowSize
);
for
(
int
i
=
1
;
i
<
pFillInfo
->
numOfCols
;
i
++
)
{
SFillColInfo
*
pCol
=
&
pFillInfo
->
pFillCol
[
i
];
...
...
@@ -393,9 +180,9 @@ static int32_t fillResultImpl(SFillInfo* pFillInfo, tFilePage** data, int32_t ou
while
(
pFillInfo
->
numOfCurrent
<
outputRows
)
{
int64_t
ts
=
((
int64_t
*
)
pFillInfo
->
pData
[
0
])[
pFillInfo
->
index
];
// set the next value for interpolation
if
((
pFillInfo
->
currentKey
<
ts
&&
FILL_IS_ASC_FILL
(
pFillInfo
))
||
(
pFillInfo
->
currentKey
>
ts
&&
!
FILL_IS_ASC_FILL
(
pFillInfo
)))
{
/* set the next value for interpolation */
initBeforeAfterDataBuf
(
pFillInfo
,
next
);
copyCurrentRowIntoBuf
(
pFillInfo
,
srcData
,
*
next
);
}
...
...
@@ -449,7 +236,7 @@ static int32_t fillResultImpl(SFillInfo* pFillInfo, tFilePage** data, int32_t ou
setTagsValue
(
pFillInfo
,
data
,
pFillInfo
->
numOfCurrent
);
pFillInfo
->
currentKey
=
taosTimeAdd
(
pFillInfo
->
currentKey
,
pFillInfo
->
interval
.
sliding
*
step
,
pFillInfo
->
interval
.
slidingUnit
,
pFillInfo
->
precision
);
pFillInfo
->
interval
.
slidingUnit
,
pFillInfo
->
precision
);
pFillInfo
->
index
+=
1
;
pFillInfo
->
numOfCurrent
+=
1
;
}
...
...
@@ -468,7 +255,7 @@ static int32_t fillResultImpl(SFillInfo* pFillInfo, tFilePage** data, int32_t ou
return
pFillInfo
->
numOfCurrent
;
}
static
int64_t
fillExternalResults
(
SFillInfo
*
pFillInfo
,
tFilePage
**
output
,
int64_t
resultCapacity
)
{
static
int64_t
appendFilledResult
(
SFillInfo
*
pFillInfo
,
tFilePage
**
output
,
int64_t
resultCapacity
)
{
/*
* These data are generated according to fill strategy, since the current timestamp is out of the time window of
* real result set. Note that we need to keep the direct previous result rows, to generated the filled data.
...
...
@@ -484,15 +271,246 @@ static int64_t fillExternalResults(SFillInfo* pFillInfo, tFilePage** output, int
return
resultCapacity
;
}
// there are no duplicated tags in the SFillTagColInfo list
static
int32_t
setTagColumnInfo
(
SFillInfo
*
pFillInfo
,
int32_t
numOfCols
,
int32_t
capacity
)
{
int32_t
rowsize
=
0
;
int32_t
k
=
0
;
for
(
int32_t
i
=
0
;
i
<
numOfCols
;
++
i
)
{
SFillColInfo
*
pColInfo
=
&
pFillInfo
->
pFillCol
[
i
];
pFillInfo
->
pData
[
i
]
=
calloc
(
1
,
pColInfo
->
col
.
bytes
*
capacity
);
if
(
TSDB_COL_IS_TAG
(
pColInfo
->
flag
))
{
bool
exists
=
false
;
int32_t
index
=
-
1
;
for
(
int32_t
j
=
0
;
j
<
k
;
++
j
)
{
if
(
pFillInfo
->
pTags
[
j
].
col
.
colId
==
pColInfo
->
col
.
colId
)
{
exists
=
true
;
index
=
j
;
break
;
}
}
if
(
!
exists
)
{
SSchema
*
pSchema
=
&
pFillInfo
->
pTags
[
k
].
col
;
pSchema
->
colId
=
pColInfo
->
col
.
colId
;
pSchema
->
type
=
pColInfo
->
col
.
type
;
pSchema
->
bytes
=
pColInfo
->
col
.
bytes
;
pFillInfo
->
pTags
[
k
].
tagVal
=
calloc
(
1
,
pColInfo
->
col
.
bytes
);
pColInfo
->
tagIndex
=
k
;
k
+=
1
;
}
else
{
pColInfo
->
tagIndex
=
index
;
}
}
rowsize
+=
pColInfo
->
col
.
bytes
;
}
assert
(
k
<=
pFillInfo
->
numOfTags
);
return
rowsize
;
}
static
int32_t
taosNumOfRemainRows
(
SFillInfo
*
pFillInfo
)
{
if
(
pFillInfo
->
numOfRows
==
0
||
(
pFillInfo
->
numOfRows
>
0
&&
pFillInfo
->
index
>=
pFillInfo
->
numOfRows
))
{
return
0
;
}
return
pFillInfo
->
numOfRows
-
pFillInfo
->
index
;
}
SFillInfo
*
taosInitFillInfo
(
int32_t
order
,
TSKEY
skey
,
int32_t
numOfTags
,
int32_t
capacity
,
int32_t
numOfCols
,
int64_t
slidingTime
,
int8_t
slidingUnit
,
int8_t
precision
,
int32_t
fillType
,
SFillColInfo
*
pCol
,
void
*
handle
)
{
if
(
fillType
==
TSDB_FILL_NONE
)
{
return
NULL
;
}
SFillInfo
*
pFillInfo
=
calloc
(
1
,
sizeof
(
SFillInfo
));
taosResetFillInfo
(
pFillInfo
,
skey
);
pFillInfo
->
order
=
order
;
pFillInfo
->
type
=
fillType
;
pFillInfo
->
pFillCol
=
pCol
;
pFillInfo
->
numOfTags
=
numOfTags
;
pFillInfo
->
numOfCols
=
numOfCols
;
pFillInfo
->
precision
=
precision
;
pFillInfo
->
alloc
=
capacity
;
pFillInfo
->
handle
=
handle
;
pFillInfo
->
interval
.
interval
=
slidingTime
;
pFillInfo
->
interval
.
intervalUnit
=
slidingUnit
;
pFillInfo
->
interval
.
sliding
=
slidingTime
;
pFillInfo
->
interval
.
slidingUnit
=
slidingUnit
;
pFillInfo
->
pData
=
malloc
(
POINTER_BYTES
*
numOfCols
);
if
(
numOfTags
>
0
)
{
pFillInfo
->
pTags
=
calloc
(
pFillInfo
->
numOfTags
,
sizeof
(
SFillTagColInfo
));
for
(
int32_t
i
=
0
;
i
<
numOfTags
;
++
i
)
{
pFillInfo
->
pTags
[
i
].
col
.
colId
=
-
2
;
// TODO
}
}
pFillInfo
->
rowSize
=
setTagColumnInfo
(
pFillInfo
,
pFillInfo
->
numOfCols
,
pFillInfo
->
alloc
);
assert
(
pFillInfo
->
rowSize
>
0
);
return
pFillInfo
;
}
void
taosResetFillInfo
(
SFillInfo
*
pFillInfo
,
TSKEY
startTimestamp
)
{
pFillInfo
->
start
=
startTimestamp
;
pFillInfo
->
currentKey
=
startTimestamp
;
pFillInfo
->
index
=
-
1
;
pFillInfo
->
numOfRows
=
0
;
pFillInfo
->
numOfCurrent
=
0
;
pFillInfo
->
numOfTotal
=
0
;
}
void
*
taosDestroyFillInfo
(
SFillInfo
*
pFillInfo
)
{
if
(
pFillInfo
==
NULL
)
{
return
NULL
;
}
tfree
(
pFillInfo
->
prevValues
);
tfree
(
pFillInfo
->
nextValues
);
tfree
(
pFillInfo
->
pTags
);
for
(
int32_t
i
=
0
;
i
<
pFillInfo
->
numOfCols
;
++
i
)
{
tfree
(
pFillInfo
->
pData
[
i
]);
}
tfree
(
pFillInfo
->
pData
);
tfree
(
pFillInfo
->
pFillCol
);
tfree
(
pFillInfo
);
return
NULL
;
}
void
taosFillSetStartInfo
(
SFillInfo
*
pFillInfo
,
int32_t
numOfRows
,
TSKEY
endKey
)
{
if
(
pFillInfo
->
type
==
TSDB_FILL_NONE
)
{
return
;
}
pFillInfo
->
end
=
endKey
;
if
(
!
FILL_IS_ASC_FILL
(
pFillInfo
))
{
pFillInfo
->
end
=
taosTimeTruncate
(
endKey
,
&
pFillInfo
->
interval
,
pFillInfo
->
precision
);
}
pFillInfo
->
index
=
0
;
pFillInfo
->
numOfRows
=
numOfRows
;
// ensure the space
if
(
pFillInfo
->
alloc
<
numOfRows
)
{
for
(
int32_t
i
=
0
;
i
<
pFillInfo
->
numOfCols
;
++
i
)
{
char
*
tmp
=
realloc
(
pFillInfo
->
pData
[
i
],
numOfRows
*
pFillInfo
->
pFillCol
[
i
].
col
.
bytes
);
assert
(
tmp
!=
NULL
);
// todo handle error
memset
(
tmp
,
0
,
numOfRows
*
pFillInfo
->
pFillCol
[
i
].
col
.
bytes
);
pFillInfo
->
pData
[
i
]
=
tmp
;
}
}
}
// copy the data into source data buffer
void
taosFillCopyInputDataFromFilePage
(
SFillInfo
*
pFillInfo
,
const
tFilePage
**
pInput
)
{
for
(
int32_t
i
=
0
;
i
<
pFillInfo
->
numOfCols
;
++
i
)
{
memcpy
(
pFillInfo
->
pData
[
i
],
pInput
[
i
]
->
data
,
pFillInfo
->
numOfRows
*
pFillInfo
->
pFillCol
[
i
].
col
.
bytes
);
}
}
void
taosFillCopyInputDataFromOneFilePage
(
SFillInfo
*
pFillInfo
,
const
tFilePage
*
pInput
)
{
assert
(
pFillInfo
->
numOfRows
==
pInput
->
num
);
for
(
int32_t
i
=
0
;
i
<
pFillInfo
->
numOfCols
;
++
i
)
{
SFillColInfo
*
pCol
=
&
pFillInfo
->
pFillCol
[
i
];
const
char
*
data
=
pInput
->
data
+
pCol
->
col
.
offset
*
pInput
->
num
;
memcpy
(
pFillInfo
->
pData
[
i
],
data
,
(
size_t
)(
pInput
->
num
*
pCol
->
col
.
bytes
));
if
(
TSDB_COL_IS_TAG
(
pCol
->
flag
))
{
// copy the tag value to tag value buffer
SFillTagColInfo
*
pTag
=
&
pFillInfo
->
pTags
[
pCol
->
tagIndex
];
assert
(
pTag
->
col
.
colId
==
pCol
->
col
.
colId
);
memcpy
(
pTag
->
tagVal
,
data
,
pCol
->
col
.
bytes
);
}
}
}
bool
taosFillHasMoreResults
(
SFillInfo
*
pFillInfo
)
{
return
taosNumOfRemainRows
(
pFillInfo
)
>
0
;
}
int64_t
getNumOfResultsAfterFillGap
(
SFillInfo
*
pFillInfo
,
TSKEY
ekey
,
int32_t
maxNumOfRows
)
{
int64_t
*
tsList
=
(
int64_t
*
)
pFillInfo
->
pData
[
0
];
int32_t
numOfRows
=
taosNumOfRemainRows
(
pFillInfo
);
TSKEY
ekey1
=
ekey
;
if
(
!
FILL_IS_ASC_FILL
(
pFillInfo
))
{
pFillInfo
->
end
=
taosTimeTruncate
(
ekey
,
&
pFillInfo
->
interval
,
pFillInfo
->
precision
);
}
int64_t
numOfRes
=
-
1
;
if
(
numOfRows
>
0
)
{
// still fill gap within current data block, not generating data after the result set.
TSKEY
lastKey
=
tsList
[
pFillInfo
->
numOfRows
-
1
];
numOfRes
=
taosTimeCountInterval
(
lastKey
,
pFillInfo
->
currentKey
,
pFillInfo
->
interval
.
sliding
,
pFillInfo
->
interval
.
slidingUnit
,
pFillInfo
->
precision
);
numOfRes
+=
1
;
assert
(
numOfRes
>=
numOfRows
);
}
else
{
// reach the end of data
if
((
ekey1
<
pFillInfo
->
currentKey
&&
FILL_IS_ASC_FILL
(
pFillInfo
))
||
(
ekey1
>
pFillInfo
->
currentKey
&&
!
FILL_IS_ASC_FILL
(
pFillInfo
)))
{
return
0
;
}
numOfRes
=
taosTimeCountInterval
(
ekey1
,
pFillInfo
->
currentKey
,
pFillInfo
->
interval
.
sliding
,
pFillInfo
->
interval
.
slidingUnit
,
pFillInfo
->
precision
);
numOfRes
+=
1
;
}
return
(
numOfRes
>
maxNumOfRows
)
?
maxNumOfRows
:
numOfRes
;
}
int32_t
taosGetLinearInterpolationVal
(
int32_t
type
,
SPoint
*
point1
,
SPoint
*
point2
,
SPoint
*
point
)
{
double
v1
=
-
1
;
double
v2
=
-
1
;
GET_TYPED_DATA
(
v1
,
double
,
type
,
point1
->
val
);
GET_TYPED_DATA
(
v2
,
double
,
type
,
point2
->
val
);
double
r
=
DO_INTERPOLATION
(
v1
,
v2
,
point1
->
key
,
point2
->
key
,
point
->
key
);
switch
(
type
)
{
case
TSDB_DATA_TYPE_TINYINT
:
*
(
int8_t
*
)
point
->
val
=
(
int8_t
)
r
;
break
;
case
TSDB_DATA_TYPE_SMALLINT
:
*
(
int16_t
*
)
point
->
val
=
(
int16_t
)
r
;
break
;
case
TSDB_DATA_TYPE_INT
:
*
(
int32_t
*
)
point
->
val
=
(
int32_t
)
r
;
break
;
case
TSDB_DATA_TYPE_BIGINT
:
*
(
int64_t
*
)
point
->
val
=
(
int64_t
)
r
;
break
;
case
TSDB_DATA_TYPE_DOUBLE
:
*
(
double
*
)
point
->
val
=
(
double
)
r
;
break
;
case
TSDB_DATA_TYPE_FLOAT
:
*
(
float
*
)
point
->
val
=
(
float
)
r
;
break
;
default:
assert
(
0
);
}
return
TSDB_CODE_SUCCESS
;
}
int64_t
taosFillResultDataBlock
(
SFillInfo
*
pFillInfo
,
tFilePage
**
output
,
int32_t
capacity
)
{
int32_t
remain
=
taosNumOfRemainRows
(
pFillInfo
);
int64_t
numOfRes
=
getNumOfRes
WithFill
(
pFillInfo
,
pFillInfo
->
end
,
capacity
);
int64_t
numOfRes
=
getNumOfRes
ultsAfterFillGap
(
pFillInfo
,
pFillInfo
->
end
,
capacity
);
assert
(
numOfRes
<=
capacity
);
// no data existed for fill operation now, append result according to the fill strategy
if
(
remain
==
0
)
{
fillExternalResults
(
pFillInfo
,
output
,
numOfRes
);
appendFilledResult
(
pFillInfo
,
output
,
numOfRes
);
}
else
{
fillResultImpl
(
pFillInfo
,
output
,
(
int32_t
)
numOfRes
);
assert
(
numOfRes
==
pFillInfo
->
numOfCurrent
);
...
...
src/query/src/qHistogram.c
浏览文件 @
c1b456be
...
...
@@ -184,7 +184,7 @@ int32_t tHistogramAdd(SHistogramInfo** pHisto, double val) {
histogramCreateBin
(
*
pHisto
,
idx
,
val
);
}
#else
tSkipListKey
key
=
tSkipListCreateKey
(
TSDB_DATA_TYPE_DOUBLE
,
&
val
,
tDataType
Desc
[
TSDB_DATA_TYPE_DOUBLE
].
nSize
);
tSkipListKey
key
=
tSkipListCreateKey
(
TSDB_DATA_TYPE_DOUBLE
,
&
val
,
tDataType
s
[
TSDB_DATA_TYPE_DOUBLE
].
nSize
);
SHistBin
*
entry
=
calloc
(
1
,
sizeof
(
SHistBin
));
entry
->
val
=
val
;
...
...
@@ -217,7 +217,7 @@ int32_t tHistogramAdd(SHistogramInfo** pHisto, double val) {
}
tSkipListKey
kx
=
tSkipListCreateKey
(
TSDB_DATA_TYPE_DOUBLE
,
&
(
*
pHisto
)
->
max
,
tDataType
Desc
[
TSDB_DATA_TYPE_DOUBLE
].
nSize
);
tSkipListCreateKey
(
TSDB_DATA_TYPE_DOUBLE
,
&
(
*
pHisto
)
->
max
,
tDataType
s
[
TSDB_DATA_TYPE_DOUBLE
].
nSize
);
pLast
=
tSkipListGetOne
((
*
pHisto
)
->
pList
,
&
kx
);
}
}
else
{
...
...
src/query/src/qParserImpl.c
浏览文件 @
c1b456be
...
...
@@ -398,21 +398,21 @@ void tSqlSetColumnType(TAOS_FIELD *pField, SStrToken *type) {
pField
->
name
[
0
]
=
0
;
int32_t
i
=
0
;
while
(
i
<
tListLen
(
tDataType
Desc
))
{
if
((
type
->
n
==
tDataType
Desc
[
i
].
nameLen
)
&&
(
strncasecmp
(
type
->
z
,
tDataType
Desc
[
i
].
aName
,
tDataTypeDesc
[
i
].
nameLen
)
==
0
))
{
while
(
i
<
tListLen
(
tDataType
s
))
{
if
((
type
->
n
==
tDataType
s
[
i
].
nameLen
)
&&
(
strncasecmp
(
type
->
z
,
tDataType
s
[
i
].
name
,
tDataTypes
[
i
].
nameLen
)
==
0
))
{
break
;
}
i
+=
1
;
}
if
(
i
==
tListLen
(
tDataType
Desc
))
{
if
(
i
==
tListLen
(
tDataType
s
))
{
return
;
}
pField
->
type
=
i
;
pField
->
bytes
=
tDataType
Desc
[
i
].
nSize
;
pField
->
bytes
=
tDataType
s
[
i
].
bytes
;
if
(
i
==
TSDB_DATA_TYPE_NCHAR
)
{
/*
...
...
src/query/tests/percentileTest.cpp
浏览文件 @
c1b456be
...
...
@@ -43,7 +43,7 @@ tMemBucket *createDoubleDataBucket(int32_t start, int32_t end) {
}
tMemBucket
*
createUnsignedDataBucket
(
int32_t
start
,
int32_t
end
,
int32_t
type
)
{
tMemBucket
*
pBucket
=
tMemBucketCreate
(
tDataType
Desc
[
type
].
nSize
,
type
,
start
,
end
);
tMemBucket
*
pBucket
=
tMemBucketCreate
(
tDataType
s
[
type
].
nSize
,
type
,
start
,
end
);
for
(
int32_t
i
=
start
;
i
<=
end
;
++
i
)
{
uint64_t
k
=
i
;
int32_t
ret
=
tMemBucketPut
(
pBucket
,
&
k
,
1
);
...
...
src/tsdb/src/tsdbCommit.c
浏览文件 @
c1b456be
...
...
@@ -763,10 +763,10 @@ static int tsdbWriteBlock(SCommitH *pCommith, SDFile *pDFile, SDataCols *pDataCo
pBlockCol
->
colId
=
pDataCol
->
colId
;
pBlockCol
->
type
=
pDataCol
->
type
;
if
(
tDataType
Desc
[
pDataCol
->
type
].
getStatisFunc
)
{
(
*
tDataType
Desc
[
pDataCol
->
type
].
getStatisFunc
)(
pDataCol
->
pData
,
rowsToWrite
,
&
(
pBlockCol
->
min
),
&
(
pBlockCol
->
max
),
&
(
pBlockCol
->
sum
),
&
(
pBlockCol
->
minIndex
),
&
(
pBlockCol
->
maxIndex
),
&
(
pBlockCol
->
numOfNull
));
if
(
tDataType
s
[
pDataCol
->
type
].
getStatisFunc
)
{
(
*
tDataType
s
[
pDataCol
->
type
].
getStatisFunc
)(
pDataCol
->
pData
,
rowsToWrite
,
&
(
pBlockCol
->
min
),
&
(
pBlockCol
->
max
),
&
(
pBlockCol
->
sum
),
&
(
pBlockCol
->
minIndex
),
&
(
pBlockCol
->
maxIndex
),
&
(
pBlockCol
->
numOfNull
));
}
nColsNotAllNull
++
;
}
...
...
@@ -806,9 +806,9 @@ static int tsdbWriteBlock(SCommitH *pCommith, SDFile *pDFile, SDataCols *pDataCo
// Compress or just copy
if
(
pCfg
->
compression
)
{
flen
=
(
*
(
tDataType
Desc
[
pDataCol
->
type
].
compFunc
))((
char
*
)
pDataCol
->
pData
,
tlen
,
rowsToWrite
,
tptr
,
tlen
+
COMP_OVERFLOW_BYTES
,
pCfg
->
compression
,
TSDB_COMMIT_COMP_BUF
(
pCommith
),
tlen
+
COMP_OVERFLOW_BYTES
);
flen
=
(
*
(
tDataType
s
[
pDataCol
->
type
].
compFunc
))((
char
*
)
pDataCol
->
pData
,
tlen
,
rowsToWrite
,
tptr
,
tlen
+
COMP_OVERFLOW_BYTES
,
pCfg
->
compression
,
TSDB_COMMIT_COMP_BUF
(
pCommith
),
tlen
+
COMP_OVERFLOW_BYTES
);
}
else
{
flen
=
tlen
;
memcpy
(
tptr
,
pDataCol
->
pData
,
flen
);
...
...
src/tsdb/src/tsdbMeta.c
浏览文件 @
c1b456be
...
...
@@ -245,7 +245,7 @@ STableCfg *tsdbCreateTableCfgFromMsg(SMDCreateTableMsg *pMsg) {
}
}
if
(
tsdbTableSetSchema
(
pCfg
,
tdGetSchemaFromBuilder
(
&
schemaBuilder
),
false
)
<
0
)
goto
_err
;
if
(
tsdbTableSetName
(
pCfg
,
pMsg
->
table
Id
,
true
)
<
0
)
goto
_err
;
if
(
tsdbTableSetName
(
pCfg
,
pMsg
->
table
Fname
,
true
)
<
0
)
goto
_err
;
if
(
numOfTags
>
0
)
{
// Decode tag schema
...
...
@@ -257,7 +257,7 @@ STableCfg *tsdbCreateTableCfgFromMsg(SMDCreateTableMsg *pMsg) {
}
}
if
(
tsdbTableSetTagSchema
(
pCfg
,
tdGetSchemaFromBuilder
(
&
schemaBuilder
),
false
)
<
0
)
goto
_err
;
if
(
tsdbTableSetSName
(
pCfg
,
pMsg
->
s
uperTableId
,
true
)
<
0
)
goto
_err
;
if
(
tsdbTableSetSName
(
pCfg
,
pMsg
->
s
tableFname
,
true
)
<
0
)
goto
_err
;
if
(
tsdbTableSetSuperUid
(
pCfg
,
htobe64
(
pMsg
->
superTableUid
))
<
0
)
goto
_err
;
int32_t
tagDataLen
=
htonl
(
pMsg
->
tagDataLen
);
...
...
src/tsdb/src/tsdbReadImpl.c
浏览文件 @
c1b456be
...
...
@@ -515,7 +515,7 @@ static int tsdbCheckAndDecodeColumnData(SDataCol *pDataCol, void *content, int32
// Decode the data
if
(
comp
)
{
// Need to decompress
int
tlen
=
(
*
(
tDataType
Desc
[
pDataCol
->
type
].
decompFunc
))(
content
,
len
-
sizeof
(
TSCKSUM
),
numOfRows
,
pDataCol
->
pData
,
int
tlen
=
(
*
(
tDataType
s
[
pDataCol
->
type
].
decompFunc
))(
content
,
len
-
sizeof
(
TSCKSUM
),
numOfRows
,
pDataCol
->
pData
,
pDataCol
->
spaceSize
,
comp
,
buffer
,
bufferSize
);
if
(
tlen
<=
0
)
{
tsdbError
(
"Failed to decompress column, file corrupted, len:%d comp:%d numOfRows:%d maxPoints:%d bufferSize:%d"
,
...
...
src/util/src/tcompare.c
浏览文件 @
c1b456be
#include "t
aosdef
.h"
#include "t
type
.h"
#include "tcompare.h"
#include "tarray.h"
...
...
src/vnode/src/vnodeWrite.c
浏览文件 @
c1b456be
...
...
@@ -174,7 +174,7 @@ static int32_t vnodeProcessDropTableMsg(SVnodeObj *pVnode, void *pCont, SRspRet
SMDDropTableMsg
*
pTable
=
pCont
;
int32_t
code
=
TSDB_CODE_SUCCESS
;
vDebug
(
"vgId:%d, table:%s, start to drop"
,
pVnode
->
vgId
,
pTable
->
table
Id
);
vDebug
(
"vgId:%d, table:%s, start to drop"
,
pVnode
->
vgId
,
pTable
->
table
Fname
);
STableId
tableId
=
{.
uid
=
htobe64
(
pTable
->
uid
),
.
tid
=
htonl
(
pTable
->
tid
)};
if
(
tsdbDropTable
(
pVnode
->
tsdb
,
tableId
)
<
0
)
code
=
terrno
;
...
...
@@ -197,13 +197,13 @@ static int32_t vnodeProcessDropStableMsg(SVnodeObj *pVnode, void *pCont, SRspRet
SDropSTableMsg
*
pTable
=
pCont
;
int32_t
code
=
TSDB_CODE_SUCCESS
;
vDebug
(
"vgId:%d, stable:%s, start to drop"
,
pVnode
->
vgId
,
pTable
->
table
Id
);
vDebug
(
"vgId:%d, stable:%s, start to drop"
,
pVnode
->
vgId
,
pTable
->
table
Fname
);
STableId
stableId
=
{.
uid
=
htobe64
(
pTable
->
uid
),
.
tid
=
-
1
};
if
(
tsdbDropTable
(
pVnode
->
tsdb
,
stableId
)
<
0
)
code
=
terrno
;
vDebug
(
"vgId:%d, stable:%s, drop stable result:%s"
,
pVnode
->
vgId
,
pTable
->
table
Id
,
tstrerror
(
code
));
vDebug
(
"vgId:%d, stable:%s, drop stable result:%s"
,
pVnode
->
vgId
,
pTable
->
table
Fname
,
tstrerror
(
code
));
return
code
;
}
...
...
tests/examples/c/asyncdemo.c
浏览文件 @
c1b456be
...
...
@@ -261,9 +261,6 @@ void taos_select_call_back(void *param, TAOS_RES *tres, int code)
if
(
code
==
0
&&
tres
)
{
// asynchronous API to fetch a batch of records
taos_fetch_rows_a
(
tres
,
taos_retrieve_call_back
,
pTable
);
// taos_fetch_row_a is a less efficient way to retrieve records since it call back app for every row
// taos_fetch_row_a(tres, taos_fetch_row_call_back, pTable);
}
else
{
printf
(
"%s select failed, code:%d
\n
"
,
pTable
->
name
,
code
);
...
...
tests/examples/c/demo.c
浏览文件 @
c1b456be
...
...
@@ -93,15 +93,15 @@ void Test(TAOS *taos, char *qstr, int index) {
// if (taos_query(taos, qstr)) {
// printf("insert row: %i, reason:%s\n", i, taos_errstr(taos));
// }
TAOS_RES
*
result
=
taos_query
(
taos
,
qstr
);
if
(
result
)
{
TAOS_RES
*
result
1
=
taos_query
(
taos
,
qstr
);
if
(
result
1
)
{
printf
(
"insert row: %i
\n
"
,
i
);
}
else
{
printf
(
"failed to insert row: %i, reason:%s
\n
"
,
i
,
"null result"
/*taos_errstr(result)*/
);
taos_free_result
(
result
);
taos_free_result
(
result
1
);
exit
(
1
);
}
taos_free_result
(
result
);
taos_free_result
(
result
1
);
}
printf
(
"success to insert rows, total %d rows
\n
"
,
i
);
...
...
tests/script/general/parser/columnValue_unsign.sim
浏览文件 @
c1b456be
...
...
@@ -111,7 +111,8 @@ if $rows != 1 then
return -1
endi
if $data00 != 6.000000000 then
if $data00 != NULL then
print expect NULL, actual:$data00
return -1
endi
...
...
@@ -167,7 +168,7 @@ if $data01 != 4 then
return -1
endi
//
todo insert more rows and chec it
##
todo insert more rows and chec it
sql select first(a),count(b),last(c),sum(b),spread(d),avg(c),min(b),max(a),stddev(a) from mt_unsigned_1;
if $rows != 1 then
return -1
...
...
tests/script/general/parser/testSuite.sim
浏览文件 @
c1b456be
#
run general/parser/alter.sim
#
sleep 100
#
run general/parser/alter1.sim
#
sleep 100
#
run general/parser/alter_stable.sim
#
sleep 100
#
run general/parser/auto_create_tb.sim
#
sleep 100
#
run general/parser/auto_create_tb_drop_tb.sim
#
sleep 100
#
run general/parser/col_arithmetic_operation.sim
#
sleep 100
#
run general/parser/columnValue.sim
#
sleep 100
#
run general/parser/commit.sim
#
sleep 100
#
run general/parser/create_db.sim
#
sleep 100
#
run general/parser/create_mt.sim
#
sleep 100
#
run general/parser/create_tb.sim
#
sleep 100
#
run general/parser/dbtbnameValidate.sim
#
sleep 100
#
run general/parser/fill.sim
#
sleep 100
#
run general/parser/fill_stb.sim
#
sleep 100
#
#
run general/parser/fill_us.sim #
#
sleep 100
#
run general/parser/first_last.sim
#
sleep 100
#
run general/parser/import_commit1.sim
#
sleep 100
#
run general/parser/import_commit2.sim
#
sleep 100
#
run general/parser/import_commit3.sim
#
sleep 100
#
#
run general/parser/import_file.sim
#
sleep 100
#
run general/parser/insert_tb.sim
#
sleep 100
#
run general/parser/tags_dynamically_specifiy.sim
#
sleep 100
#
run general/parser/interp.sim
#
sleep 100
#
run general/parser/lastrow.sim
#
sleep 100
#
run general/parser/limit.sim
#
sleep 100
#
run general/parser/limit1.sim
#
sleep 100
#
run general/parser/limit1_tblocks100.sim
#
sleep 100
#
run general/parser/limit2.sim
#
sleep 100
#
run general/parser/mixed_blocks.sim
#
sleep 100
#
run general/parser/nchar.sim
#
sleep 100
#
run general/parser/null_char.sim
run general/parser/alter.sim
sleep 100
run general/parser/alter1.sim
sleep 100
run general/parser/alter_stable.sim
sleep 100
run general/parser/auto_create_tb.sim
sleep 100
run general/parser/auto_create_tb_drop_tb.sim
sleep 100
run general/parser/col_arithmetic_operation.sim
sleep 100
run general/parser/columnValue.sim
sleep 100
run general/parser/commit.sim
sleep 100
run general/parser/create_db.sim
sleep 100
run general/parser/create_mt.sim
sleep 100
run general/parser/create_tb.sim
sleep 100
run general/parser/dbtbnameValidate.sim
sleep 100
run general/parser/fill.sim
sleep 100
run general/parser/fill_stb.sim
sleep 100
#run general/parser/fill_us.sim #
sleep 100
run general/parser/first_last.sim
sleep 100
run general/parser/import_commit1.sim
sleep 100
run general/parser/import_commit2.sim
sleep 100
run general/parser/import_commit3.sim
sleep 100
#run general/parser/import_file.sim
sleep 100
run general/parser/insert_tb.sim
sleep 100
run general/parser/tags_dynamically_specifiy.sim
sleep 100
run general/parser/interp.sim
sleep 100
run general/parser/lastrow.sim
sleep 100
run general/parser/limit.sim
sleep 100
run general/parser/limit1.sim
sleep 100
run general/parser/limit1_tblocks100.sim
sleep 100
run general/parser/limit2.sim
sleep 100
run general/parser/mixed_blocks.sim
sleep 100
run general/parser/nchar.sim
sleep 100
run general/parser/null_char.sim
sleep 100
run general/parser/selectResNum.sim
sleep 100
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录