Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
990205d6
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
990205d6
编写于
4月 27, 2022
作者:
wmmhello
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor: schemaless tmp commit
上级
9eff7ff4
变更
15
展开全部
显示空白变更内容
内联
并排
Showing
15 changed file
with
554 addition
and
2777 deletion
+554
-2777
include/common/tcommon.h
include/common/tcommon.h
+9
-0
include/libs/parser/parser.h
include/libs/parser/parser.h
+5
-1
include/util/tdef.h
include/util/tdef.h
+4
-0
source/client/inc/clientSml.h
source/client/inc/clientSml.h
+34
-44
source/client/schemaless/CMakeLists.txt
source/client/schemaless/CMakeLists.txt
+0
-17
source/client/schemaless/src/tscParseOpenTSDB.c
source/client/schemaless/src/tscParseOpenTSDB.c
+0
-1113
source/client/src/clientSml.c
source/client/src/clientSml.c
+269
-1510
source/client/src/clientStmt.c
source/client/src/clientStmt.c
+1
-1
source/libs/parser/inc/parInsertData.h
source/libs/parser/inc/parInsertData.h
+1
-1
source/libs/parser/inc/parUtil.h
source/libs/parser/inc/parUtil.h
+0
-1
source/libs/parser/src/parInsert.c
source/libs/parser/src/parInsert.c
+214
-14
source/libs/parser/src/parInsertData.c
source/libs/parser/src/parInsertData.c
+6
-8
source/libs/parser/src/parUtil.c
source/libs/parser/src/parUtil.c
+0
-20
tools/shell/src/shellCommand.c
tools/shell/src/shellCommand.c
+2
-2
tools/shell/src/shellEngine.c
tools/shell/src/shellEngine.c
+9
-45
未找到文件。
include/common/tcommon.h
浏览文件 @
990205d6
...
...
@@ -241,6 +241,15 @@ typedef struct SExprInfo {
struct
tExprNode
*
pExpr
;
}
SExprInfo
;
typedef
struct
{
const
char
*
key
;
int32_t
keyLen
;
uint8_t
type
;
int16_t
length
;
const
char
*
value
;
int32_t
valueLen
;
}
SSmlKv
;
#define QUERY_ASC_FORWARD_STEP 1
#define QUERY_DESC_FORWARD_STEP -1
...
...
include/libs/parser/parser.h
浏览文件 @
990205d6
...
...
@@ -92,10 +92,14 @@ int32_t qBindStmtColsValue(void *pBlock, TAOS_BIND_v2 *bind, char *msgBuf, int32
int32_t
qBindStmtSingleColValue
(
void
*
pBlock
,
TAOS_BIND_v2
*
bind
,
char
*
msgBuf
,
int32_t
msgBufLen
,
int32_t
colIdx
,
int32_t
rowNum
);
int32_t
qBuildStmtColFields
(
void
*
pDataBlock
,
int32_t
*
fieldNum
,
TAOS_FIELD
**
fields
);
int32_t
qBuildStmtTagFields
(
void
*
pBlock
,
void
*
boundTags
,
int32_t
*
fieldNum
,
TAOS_FIELD
**
fields
);
int32_t
qBindStmtTagsValue
(
void
*
pBlock
,
void
*
boundTags
,
int64_t
suid
,
SName
*
p
Name
,
TAOS_BIND_v2
*
bind
,
char
*
msgBuf
,
int32_t
msgBufLen
);
int32_t
qBindStmtTagsValue
(
void
*
pBlock
,
void
*
boundTags
,
int64_t
suid
,
char
*
t
Name
,
TAOS_BIND_v2
*
bind
,
char
*
msgBuf
,
int32_t
msgBufLen
);
void
destroyBoundColumnInfo
(
void
*
pBoundInfo
);
int32_t
qCreateSName
(
SName
*
pName
,
const
char
*
pTableName
,
int32_t
acctId
,
char
*
dbName
,
char
*
msgBuf
,
int32_t
msgBufLen
);
void
*
tscSmlInitHandle
(
SQuery
*
pQuery
);
void
tscSmlDestroyHandle
(
void
*
pHandle
);
int32_t
smlBind
(
void
*
handle
,
SArray
*
tags
,
SArray
*
cols
,
STableMeta
*
pTableMeta
,
char
*
msgBuf
,
int16_t
msgBufLen
);
int32_t
smlBuildOutput
(
void
*
handle
,
SHashObj
*
pVgHash
);
#ifdef __cplusplus
}
...
...
include/util/tdef.h
浏览文件 @
990205d6
...
...
@@ -86,9 +86,13 @@ extern const int32_t TYPE_BYTES[15];
#define TS_PATH_DELIMITER "."
#define TS_ESCAPE_CHAR '`'
#define TSDB_TIME_PRECISION_MILLI 0
#define TSDB_TIME_PRECISION_MICRO 1
#define TSDB_TIME_PRECISION_NANO 2
#define TSDB_TIME_PRECISION_HOURS 3
#define TSDB_TIME_PRECISION_MINUTES 4
#define TSDB_TIME_PRECISION_SECONDS 5
#define TSDB_TIME_PRECISION_MILLI_STR "ms"
#define TSDB_TIME_PRECISION_MICRO_STR "us"
...
...
source/client/inc/
tscParseLine
.h
→
source/client/inc/
clientSml
.h
浏览文件 @
990205d6
...
...
@@ -13,30 +13,19 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef TDENGINE_
TSCPARSELINE
_H
#define TDENGINE_
TSCPARSELINE
_H
#ifndef TDENGINE_
CLIENTSML
_H
#define TDENGINE_
CLIENTSML
_H
#ifdef __cplusplus
extern
"C"
{
#endif
#include "thash.h"
#include "clientint.h"
#define SML_TIMESTAMP_SECOND_DIGITS 10
#define SML_TIMESTAMP_MILLI_SECOND_DIGITS 13
#include "clientInt.h"
#include "catalog.h"
typedef
TSDB_SML_PROTOCOL_TYPE
SMLProtocolType
;
typedef
struct
{
const
char
*
key
;
int32_t
keyLen
;
uint8_t
type
;
int16_t
length
;
const
char
*
value
;
int32_t
valueLen
;
}
TAOS_SML_KV
;
typedef
struct
{
const
char
*
measure
;
const
char
*
tags
;
...
...
@@ -50,65 +39,66 @@ typedef struct {
}
TAOS_PARSE_ELEMENTS
;
typedef
struct
{
char
*
childTableName
;
const
char
*
sTableName
;
// super table name
uint8_t
sTableNameLen
;
char
childTableName
[
TSDB_TABLE_NAME_LEN
];
uint64_t
uid
;
SArray
*
tags
;
SArray
*
cols
;
}
TAOS_SML_DATA_POINT_TAGS
;
typedef
struct
SSmlSTableMeta
{
char
*
sTableName
;
// super table name
uint8_t
sTableNameLen
;
//
char *sTableName; // super table name
//
uint8_t sTableNameLen;
uint8_t
precision
;
// the number of precision
SHashObj
*
tagHash
;
SHashObj
*
fieldHash
;
}
SSmlSTableMeta
;
typedef
enum
{
SML_TIME_STAMP_NOT_CONFIGURED
,
SML_TIME_STAMP_HOURS
,
SML_TIME_STAMP_MINUTES
,
SML_TIME_STAMP_SECONDS
,
SML_TIME_STAMP_MILLI_SECONDS
,
SML_TIME_STAMP_MICRO_SECONDS
,
SML_TIME_STAMP_NANO_SECONDS
,
SML_TIME_STAMP_NOW
}
SMLTimeStampType
;
typedef
struct
{
uint64_t
id
;
STscObj
*
taos
;
SCatalog
*
pCatalog
;
SMLProtocolType
protocol
;
SMLTimeStampType
tsType
;
int32_t
affectedRows
;
int32_t
tsType
;
SHashObj
*
childTables
;
SHashObj
*
superTables
;
SHashObj
*
metaHashObj
;
SHashObj
*
pVgHash
;
void
*
exec
;
STscObj
*
taos
;
SCatalog
*
pCatalog
;
SRequestObj
*
pRequest
;
SQuery
*
pQuery
;
int32_t
affectedRows
;
char
*
msgBuf
;
int16_t
msgLen
;
}
SSmlLinesInfo
;
int
tscSmlInsert
(
TAOS
*
taos
,
TAOS_SML_DATA_POINT
*
points
,
int
numPoint
,
SSmlLinesInfo
*
info
);
int
smlInsert
(
TAOS
*
taos
,
SSmlLinesInfo
*
info
);
bool
checkDuplicateKey
(
char
*
key
,
SHashObj
*
pHash
,
SSmlLinesInfo
*
info
);
bool
isValidInteger
(
char
*
str
);
bool
isValidFloat
(
char
*
str
);
int32_t
isValidChildTableName
(
const
char
*
pTbName
,
int16_t
len
,
SSmlLinesInfo
*
info
);
bool
convertSmlValueType
(
TAOS_SML_KV
*
pVal
,
char
*
value
,
bool
convertSmlValueType
(
SSmlKv
*
pVal
,
char
*
value
,
uint16_t
len
,
SSmlLinesInfo
*
info
,
bool
isTag
);
int32_t
convertSmlTimeStamp
(
TAOS_SML_KV
*
pVal
,
char
*
value
,
int32_t
convertSmlTimeStamp
(
SSmlKv
*
pVal
,
char
*
value
,
uint16_t
len
,
SSmlLinesInfo
*
info
);
void
destroySmlDataPoint
(
TAOS_SML_DATA_POINT
*
point
);
int
taos_insert_lines
(
TAOS
*
taos
,
char
*
lines
[],
int
numLines
,
SMLProtocolType
protocol
,
SMLTimeStampType
tsType
,
int
*
affectedRows
);
int
taos
_insert_telnet_lines
(
TAOS
*
taos
,
char
*
lines
[],
int
numLines
,
SMLProtocolType
protocol
,
int
sml_insert_lines
(
TAOS
*
taos
,
SRequestObj
*
request
,
char
*
lines
[],
int
numLines
,
SMLProtocolType
protocol
,
SMLTimeStampType
tsType
);
int
sml
_insert_telnet_lines
(
TAOS
*
taos
,
char
*
lines
[],
int
numLines
,
SMLProtocolType
protocol
,
SMLTimeStampType
tsType
,
int
*
affectedRows
);
int
taos
_insert_json_payload
(
TAOS
*
taos
,
char
*
payload
,
SMLProtocolType
protocol
,
int
sml
_insert_json_payload
(
TAOS
*
taos
,
char
*
payload
,
SMLProtocolType
protocol
,
SMLTimeStampType
tsType
,
int
*
affectedRows
);
...
...
@@ -116,4 +106,4 @@ int taos_insert_json_payload(TAOS* taos, char* payload, SMLProtocolType protocol
}
#endif
#endif // TDENGINE_
TSCPARSELINE
_H
#endif // TDENGINE_
CLIENTSML
_H
source/client/schemaless/CMakeLists.txt
已删除
100644 → 0
浏览文件 @
9eff7ff4
aux_source_directory
(
src SCHEMALESS_SRC
)
add_library
(
schemaless STATIC
${
SCHEMALESS_SRC
}
)
target_include_directories
(
schemaless
PUBLIC
"
${
TD_SOURCE_DIR
}
/include/libs/schemaless"
PRIVATE
"inc"
)
target_link_libraries
(
schemaless
PUBLIC os util common catalog qcom
)
if
(
${
BUILD_TEST
}
)
ADD_SUBDIRECTORY
(
test
)
endif
(
${
BUILD_TEST
}
)
source/client/schemaless/src/tscParseOpenTSDB.c
已删除
100644 → 0
浏览文件 @
9eff7ff4
此差异已折叠。
点击以展开。
source/client/src/
tscParseLineProtoco
l.c
→
source/client/src/
clientSm
l.c
浏览文件 @
990205d6
此差异已折叠。
点击以展开。
source/client/src/clientStmt.c
浏览文件 @
990205d6
...
...
@@ -364,7 +364,7 @@ int stmtSetTbTags(TAOS_STMT *stmt, TAOS_BIND_v2 *tags) {
STMT_ERR_RET
(
TSDB_CODE_QRY_APP_ERROR
);
}
STMT_ERR_RET
(
qBindStmtTagsValue
(
*
pDataBlock
,
pStmt
->
bInfo
.
boundTags
,
pStmt
->
bInfo
.
tbSuid
,
&
pStmt
->
bInfo
.
s
name
,
tags
,
pStmt
->
exec
.
pRequest
->
msgBuf
,
pStmt
->
exec
.
pRequest
->
msgBufLen
));
STMT_ERR_RET
(
qBindStmtTagsValue
(
*
pDataBlock
,
pStmt
->
bInfo
.
boundTags
,
pStmt
->
bInfo
.
tbSuid
,
pStmt
->
bInfo
.
sname
.
t
name
,
tags
,
pStmt
->
exec
.
pRequest
->
msgBuf
,
pStmt
->
exec
.
pRequest
->
msgBufLen
));
return
TSDB_CODE_SUCCESS
;
}
...
...
source/libs/parser/inc/parInsertData.h
浏览文件 @
990205d6
...
...
@@ -136,7 +136,7 @@ void destroyBlockHashmap(SHashObj* pDataBlockHash);
int
initRowBuilder
(
SRowBuilder
*
pBuilder
,
int16_t
schemaVer
,
SParsedDataColInfo
*
pColInfo
);
int32_t
allocateMemIfNeed
(
STableDataBlocks
*
pDataBlock
,
int32_t
rowSize
,
int32_t
*
numOfRows
);
int32_t
getDataBlockFromList
(
SHashObj
*
pHashList
,
int64_t
id
,
int32_t
size
,
int32_t
startOffset
,
int32_t
rowSize
,
const
STableMeta
*
pTableMeta
,
STableDataBlocks
**
dataBlocks
,
SArray
*
pBlockList
,
SVCreateTbReq
*
pCreateTbReq
);
STableMeta
*
pTableMeta
,
STableDataBlocks
**
dataBlocks
,
SArray
*
pBlockList
,
SVCreateTbReq
*
pCreateTbReq
);
int32_t
mergeTableDataBlocks
(
SHashObj
*
pHashObj
,
uint8_t
payloadType
,
SArray
**
pVgDataBlocks
);
int32_t
buildCreateTbMsg
(
STableDataBlocks
*
pBlocks
,
SVCreateTbReq
*
pCreateTbReq
);
int32_t
allocateMemForSize
(
STableDataBlocks
*
pDataBlock
,
int32_t
allSize
);
...
...
source/libs/parser/inc/parUtil.h
浏览文件 @
990205d6
...
...
@@ -41,7 +41,6 @@ int32_t generateSyntaxErrMsg(SMsgBuf* pBuf, int32_t errCode, ...);
int32_t
buildInvalidOperationMsg
(
SMsgBuf
*
pMsgBuf
,
const
char
*
msg
);
int32_t
buildSyntaxErrMsg
(
SMsgBuf
*
pBuf
,
const
char
*
additionalInfo
,
const
char
*
sourceStr
);
STableMeta
*
tableMetaDup
(
const
STableMeta
*
pTableMeta
);
SSchema
*
getTableColumnSchema
(
const
STableMeta
*
pTableMeta
);
SSchema
*
getTableTagSchema
(
const
STableMeta
*
pTableMeta
);
int32_t
getNumOfColumns
(
const
STableMeta
*
pTableMeta
);
...
...
source/libs/parser/src/parInsert.c
浏览文件 @
990205d6
...
...
@@ -763,11 +763,9 @@ static int32_t KvRowAppend(SMsgBuf* pMsgBuf, const void *value, int32_t len, voi
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
buildCreateTbReq
(
SVCreateTbReq
*
pTbReq
,
const
SName
*
pName
,
SKVRow
row
,
int64_t
suid
)
{
char
dbFName
[
TSDB_DB_FNAME_LEN
]
=
{
0
};
tNameGetFullDbName
(
pName
,
dbFName
);
static
int32_t
buildCreateTbReq
(
SVCreateTbReq
*
pTbReq
,
const
char
*
tname
,
SKVRow
row
,
int64_t
suid
)
{
pTbReq
->
type
=
TD_CHILD_TABLE
;
pTbReq
->
name
=
strdup
(
pName
->
tname
);
pTbReq
->
name
=
strdup
(
tname
);
pTbReq
->
ctbCfg
.
suid
=
suid
;
pTbReq
->
ctbCfg
.
pTag
=
row
;
...
...
@@ -775,7 +773,7 @@ static int32_t buildCreateTbReq(SVCreateTbReq *pTbReq, const SName* pName, SKVRo
}
// pSql -> tag1_value, ...)
static
int32_t
parseTagsClause
(
SInsertParseContext
*
pCxt
,
SSchema
*
pSchema
,
uint8_t
precision
,
const
SName
*
p
Name
)
{
static
int32_t
parseTagsClause
(
SInsertParseContext
*
pCxt
,
SSchema
*
pSchema
,
uint8_t
precision
,
const
char
*
t
Name
)
{
if
(
tdInitKVRowBuilder
(
&
pCxt
->
tagsBuilder
)
<
0
)
{
return
TSDB_CODE_TSC_OUT_OF_MEMORY
;
}
...
...
@@ -816,7 +814,7 @@ static int32_t parseTagsClause(SInsertParseContext* pCxt, SSchema* pSchema, uint
}
tdSortKVRowByColIdx
(
row
);
return
buildCreateTbReq
(
&
pCxt
->
createTblReq
,
p
Name
,
row
,
pCxt
->
pTableMeta
->
suid
);
return
buildCreateTbReq
(
&
pCxt
->
createTblReq
,
t
Name
,
row
,
pCxt
->
pTableMeta
->
suid
);
}
static
int32_t
cloneTableMeta
(
STableMeta
*
pSrc
,
STableMeta
**
pDst
)
{
...
...
@@ -876,7 +874,7 @@ static int32_t parseUsingClause(SInsertParseContext* pCxt, SToken* pTbnameToken)
if
(
TK_NK_LP
!=
sToken
.
type
)
{
return
buildSyntaxErrMsg
(
&
pCxt
->
msg
,
"( is expected"
,
sToken
.
z
);
}
CHECK_CODE
(
parseTagsClause
(
pCxt
,
pCxt
->
pTableMeta
->
schema
,
getTableInfo
(
pCxt
->
pTableMeta
).
precision
,
&
name
));
CHECK_CODE
(
parseTagsClause
(
pCxt
,
pCxt
->
pTableMeta
->
schema
,
getTableInfo
(
pCxt
->
pTableMeta
).
precision
,
name
.
t
name
));
NEXT_TOKEN
(
pCxt
->
pSql
,
sToken
);
if
(
TK_NK_RP
!=
sToken
.
type
)
{
return
buildSyntaxErrMsg
(
&
pCxt
->
msg
,
") is expected"
,
sToken
.
z
);
...
...
@@ -1024,11 +1022,6 @@ static void destroyDataBlock(STableDataBlocks* pDataBlock) {
taosMemoryFreeClear
(
pDataBlock
->
pData
);
if
(
!
pDataBlock
->
cloned
)
{
// free the refcount for metermeta
if
(
pDataBlock
->
pTableMeta
!=
NULL
)
{
taosMemoryFreeClear
(
pDataBlock
->
pTableMeta
);
}
destroyBoundColumnInfo
(
&
pDataBlock
->
boundColumnInfo
);
}
taosMemoryFreeClear
(
pDataBlock
);
...
...
@@ -1256,7 +1249,7 @@ int32_t qBuildStmtOutput(SQuery* pQuery, SHashObj* pVgHash, SHashObj* pBlockHash
return
TSDB_CODE_SUCCESS
;
}
int32_t
qBindStmtTagsValue
(
void
*
pBlock
,
void
*
boundTags
,
int64_t
suid
,
SName
*
p
Name
,
TAOS_BIND_v2
*
bind
,
char
*
msgBuf
,
int32_t
msgBufLen
){
int32_t
qBindStmtTagsValue
(
void
*
pBlock
,
void
*
boundTags
,
int64_t
suid
,
char
*
t
Name
,
TAOS_BIND_v2
*
bind
,
char
*
msgBuf
,
int32_t
msgBufLen
){
STableDataBlocks
*
pDataBlock
=
(
STableDataBlocks
*
)
pBlock
;
SMsgBuf
pBuf
=
{.
buf
=
msgBuf
,
.
len
=
msgBufLen
};
SParsedDataColInfo
*
tags
=
(
SParsedDataColInfo
*
)
boundTags
;
...
...
@@ -1297,7 +1290,7 @@ int32_t qBindStmtTagsValue(void *pBlock, void *boundTags, int64_t suid, SName *p
tdSortKVRowByColIdx
(
row
);
SVCreateTbReq
tbReq
=
{
0
};
CHECK_CODE
(
buildCreateTbReq
(
&
tbReq
,
p
Name
,
row
,
suid
));
CHECK_CODE
(
buildCreateTbReq
(
&
tbReq
,
t
Name
,
row
,
suid
));
CHECK_CODE
(
buildCreateTbMsg
(
pDataBlock
,
&
tbReq
));
destroyCreateSubTbReq
(
&
tbReq
);
...
...
@@ -1522,4 +1515,211 @@ int32_t qBuildStmtColFields(void *pBlock, int32_t *fieldNum, TAOS_FIELD** fields
}
typedef
struct
SmlExecHandle
{
SHashObj
*
pBlockHash
;
SParsedDataColInfo
tags
;
// each table
SKVRowBuilder
tagsBuilder
;
// each table
SVCreateTbReq
createTblReq
;
// each table
SQuery
*
pQuery
;
}
SmlExecHandle
;
static
int32_t
smlBoundColumns
(
SArray
*
cols
,
SParsedDataColInfo
*
pColList
,
SSchema
*
pSchema
)
{
col_id_t
nCols
=
pColList
->
numOfCols
;
pColList
->
numOfBound
=
0
;
pColList
->
boundNullLen
=
0
;
memset
(
pColList
->
boundColumns
,
0
,
sizeof
(
col_id_t
)
*
nCols
);
for
(
col_id_t
i
=
0
;
i
<
nCols
;
++
i
)
{
pColList
->
cols
[
i
].
valStat
=
VAL_STAT_NONE
;
}
bool
isOrdered
=
true
;
col_id_t
lastColIdx
=
-
1
;
// last column found
for
(
int
i
=
0
;
i
<
taosArrayGetSize
(
cols
);
++
i
)
{
SSmlKv
*
kv
=
taosArrayGetP
(
cols
,
i
);
SToken
sToken
=
{.
n
=
kv
->
keyLen
,
.
z
=
kv
->
key
};
col_id_t
t
=
lastColIdx
+
1
;
col_id_t
index
=
findCol
(
&
sToken
,
t
,
nCols
,
pSchema
);
if
(
index
<
0
&&
t
>
0
)
{
index
=
findCol
(
&
sToken
,
0
,
t
,
pSchema
);
isOrdered
=
false
;
}
if
(
index
<
0
)
{
return
TSDB_CODE_SML_INVALID_DATA
;
}
if
(
pColList
->
cols
[
index
].
valStat
==
VAL_STAT_HAS
)
{
return
TSDB_CODE_SML_INVALID_DATA
;
}
lastColIdx
=
index
;
pColList
->
cols
[
index
].
valStat
=
VAL_STAT_HAS
;
pColList
->
boundColumns
[
pColList
->
numOfBound
]
=
index
+
PRIMARYKEY_TIMESTAMP_COL_ID
;
++
pColList
->
numOfBound
;
switch
(
pSchema
[
t
].
type
)
{
case
TSDB_DATA_TYPE_BINARY
:
pColList
->
boundNullLen
+=
(
sizeof
(
VarDataOffsetT
)
+
VARSTR_HEADER_SIZE
+
CHAR_BYTES
);
break
;
case
TSDB_DATA_TYPE_NCHAR
:
pColList
->
boundNullLen
+=
(
sizeof
(
VarDataOffsetT
)
+
VARSTR_HEADER_SIZE
+
TSDB_NCHAR_SIZE
);
break
;
default:
pColList
->
boundNullLen
+=
TYPE_BYTES
[
pSchema
[
t
].
type
];
break
;
}
}
pColList
->
orderStatus
=
isOrdered
?
ORDER_STATUS_ORDERED
:
ORDER_STATUS_DISORDERED
;
if
(
!
isOrdered
)
{
pColList
->
colIdxInfo
=
taosMemoryCalloc
(
pColList
->
numOfBound
,
sizeof
(
SBoundIdxInfo
));
if
(
NULL
==
pColList
->
colIdxInfo
)
{
return
TSDB_CODE_TSC_OUT_OF_MEMORY
;
}
SBoundIdxInfo
*
pColIdx
=
pColList
->
colIdxInfo
;
for
(
col_id_t
i
=
0
;
i
<
pColList
->
numOfBound
;
++
i
)
{
pColIdx
[
i
].
schemaColIdx
=
pColList
->
boundColumns
[
i
];
pColIdx
[
i
].
boundIdx
=
i
;
}
qsort
(
pColIdx
,
pColList
->
numOfBound
,
sizeof
(
SBoundIdxInfo
),
schemaIdxCompar
);
for
(
col_id_t
i
=
0
;
i
<
pColList
->
numOfBound
;
++
i
)
{
pColIdx
[
i
].
finalIdx
=
i
;
}
qsort
(
pColIdx
,
pColList
->
numOfBound
,
sizeof
(
SBoundIdxInfo
),
boundIdxCompar
);
}
if
(
pColList
->
numOfCols
>
pColList
->
numOfBound
){
memset
(
&
pColList
->
boundColumns
[
pColList
->
numOfBound
],
0
,
sizeof
(
col_id_t
)
*
(
pColList
->
numOfCols
-
pColList
->
numOfBound
));
}
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
smlParseTags
(
SArray
*
cols
,
SKVRowBuilder
*
tagsBuilder
,
SParsedDataColInfo
*
tags
,
SSchema
*
pSchema
,
SVCreateTbReq
*
createTblReq
)
{
if
(
tdInitKVRowBuilder
(
tagsBuilder
)
<
0
)
{
return
TSDB_CODE_TSC_OUT_OF_MEMORY
;
}
SKvParam
param
=
{.
builder
=
tagsBuilder
};
for
(
int
i
=
0
;
i
<
tags
->
numOfBound
;
++
i
)
{
SSchema
*
pTagSchema
=
&
pSchema
[
tags
->
boundColumns
[
i
]
-
1
];
// colId starts with 1
param
.
schema
=
pTagSchema
;
SSmlKv
*
kv
=
taosArrayGetP
(
cols
,
i
);
KvRowAppend
(
NULL
,
kv
->
value
,
kv
->
valueLen
,
&
param
)
;
}
SKVRow
row
=
tdGetKVRowFromBuilder
(
tagsBuilder
);
if
(
row
==
NULL
){
return
TSDB_CODE_SML_INVALID_DATA
;
}
tdSortKVRowByColIdx
(
row
);
createTblReq
->
type
=
TD_CHILD_TABLE
;
createTblReq
->
ctbCfg
.
pTag
=
row
;
return
TSDB_CODE_SUCCESS
;
}
int32_t
smlBind
(
void
*
handle
,
SArray
*
tags
,
SArray
*
cols
,
STableMeta
*
pTableMeta
,
char
*
msgBuf
,
int16_t
msgBufLen
)
{
SMsgBuf
pBuf
=
{.
buf
=
msgBuf
,
.
len
=
msgBufLen
};
int32_t
rowNum
=
taosArrayGetSize
(
cols
);
if
(
rowNum
<=
0
)
{
return
buildInvalidOperationMsg
(
&
pBuf
,
"cols size <= 0"
);
}
SmlExecHandle
*
smlHandle
=
(
SmlExecHandle
*
)
handle
;
SSchema
*
pTagsSchema
=
getTableTagSchema
(
pTableMeta
);
smlBoundColumns
(
tags
,
&
smlHandle
->
tags
,
pTagsSchema
);
smlParseTags
(
tags
,
&
smlHandle
->
tagsBuilder
,
&
smlHandle
->
tags
,
pTagsSchema
,
&
smlHandle
->
createTblReq
);
STableDataBlocks
*
pDataBlock
=
NULL
;
getDataBlockFromList
(
smlHandle
->
pBlockHash
,
pTableMeta
->
uid
,
TSDB_DEFAULT_PAYLOAD_SIZE
,
sizeof
(
SSubmitBlk
),
getTableInfo
(
pTableMeta
).
rowSize
,
pTableMeta
,
&
pDataBlock
,
NULL
,
&
smlHandle
->
createTblReq
);
SSchema
*
pSchema
=
getTableColumnSchema
(
pTableMeta
);
smlBoundColumns
(
taosArrayGetP
(
cols
,
0
),
&
pDataBlock
->
boundColumnInfo
,
pSchema
);
int32_t
extendedRowSize
=
getExtendedRowSize
(
pDataBlock
);
SParsedDataColInfo
*
spd
=
&
pDataBlock
->
boundColumnInfo
;
SRowBuilder
*
pBuilder
=
&
pDataBlock
->
rowBuilder
;
SMemParam
param
=
{.
rb
=
pBuilder
};
initRowBuilder
(
&
pDataBlock
->
rowBuilder
,
pDataBlock
->
pTableMeta
->
sversion
,
&
pDataBlock
->
boundColumnInfo
);
allocateMemForSize
(
pDataBlock
,
extendedRowSize
*
rowNum
);
for
(
int32_t
r
=
0
;
r
<
rowNum
;
++
r
)
{
STSRow
*
row
=
(
STSRow
*
)(
pDataBlock
->
pData
+
pDataBlock
->
size
);
// skip the SSubmitBlk header
tdSRowResetBuf
(
pBuilder
,
row
);
SArray
*
rowData
=
taosArrayGetP
(
cols
,
r
);
// 1. set the parsed value from sql string
for
(
int
c
=
0
;
c
<
spd
->
numOfBound
;
++
c
)
{
SSchema
*
pColSchema
=
&
pSchema
[
spd
->
boundColumns
[
c
]
-
1
];
param
.
schema
=
pColSchema
;
getSTSRowAppendInfo
(
pBuilder
->
rowType
,
spd
,
c
,
&
param
.
toffset
,
&
param
.
colIdx
);
SSmlKv
*
kv
=
taosArrayGetP
(
rowData
,
c
);
if
(
kv
->
valueLen
==
0
)
{
MemRowAppend
(
&
pBuf
,
NULL
,
0
,
&
param
);
}
else
{
int32_t
colLen
=
pColSchema
->
bytes
;
if
(
IS_VAR_DATA_TYPE
(
pColSchema
->
type
))
{
colLen
=
kv
->
valueLen
;
}
MemRowAppend
(
&
pBuf
,
kv
->
value
,
colLen
,
&
param
);
}
if
(
PRIMARYKEY_TIMESTAMP_COL_ID
==
pColSchema
->
colId
)
{
TSKEY
tsKey
=
TD_ROW_KEY
(
row
);
checkTimestamp
(
pDataBlock
,
(
const
char
*
)
&
tsKey
);
}
}
// set the null value for the columns that do not assign values
if
((
spd
->
numOfBound
<
spd
->
numOfCols
)
&&
TD_IS_TP_ROW
(
row
))
{
for
(
int32_t
i
=
0
;
i
<
spd
->
numOfCols
;
++
i
)
{
if
(
spd
->
cols
[
i
].
valStat
==
VAL_STAT_NONE
)
{
// the primary TS key is not VAL_STAT_NONE
tdAppendColValToTpRow
(
pBuilder
,
TD_VTYPE_NONE
,
getNullValue
(
pSchema
[
i
].
type
),
true
,
pSchema
[
i
].
type
,
i
,
spd
->
cols
[
i
].
toffset
);
}
}
}
pDataBlock
->
size
+=
extendedRowSize
;
}
SSubmitBlk
*
pBlocks
=
(
SSubmitBlk
*
)(
pDataBlock
->
pData
);
if
(
TSDB_CODE_SUCCESS
!=
setBlockInfo
(
pBlocks
,
pDataBlock
,
rowNum
))
{
return
buildInvalidOperationMsg
(
&
pBuf
,
"too many rows in sql, total number of rows should be less than 32767"
);
}
return
TSDB_CODE_SUCCESS
;
}
void
*
tscSmlInitHandle
(
SQuery
*
pQuery
){
SmlExecHandle
*
handle
=
taosMemoryCalloc
(
sizeof
(
SmlExecHandle
));
handle
->
pBlockHash
=
taosHashInit
(
16
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BIGINT
),
true
,
false
);
handle
->
pQuery
=
pQuery
;
return
handle
;
}
void
tscSmlDestroyHandle
(
void
*
pHandle
){
if
(
!
pHandle
)
return
;
SmlExecHandle
*
handle
=
(
SmlExecHandle
*
)
pHandle
;
taosHashCleanup
(
handle
->
pBlockHash
);
taosMemoryFree
(
handle
);
}
int32_t
smlBuildOutput
(
void
*
handle
,
SHashObj
*
pVgHash
)
{
SmlExecHandle
*
smlHandle
=
(
SmlExecHandle
*
)
handle
;
return
qBuildStmtOutput
(
smlHandle
->
pQuery
,
pVgHash
,
smlHandle
->
pBlockHash
);
}
source/libs/parser/src/parInsertData.c
浏览文件 @
990205d6
...
...
@@ -116,7 +116,7 @@ void destroyBoundColumnInfo(void* pBoundInfo) {
}
static
int32_t
createDataBlock
(
size_t
defaultSize
,
int32_t
rowSize
,
int32_t
startOffset
,
const
STableMeta
*
pTableMeta
,
STableDataBlocks
**
dataBlocks
)
{
STableMeta
*
pTableMeta
,
STableDataBlocks
**
dataBlocks
)
{
STableDataBlocks
*
dataBuf
=
(
STableDataBlocks
*
)
taosMemoryCalloc
(
1
,
sizeof
(
STableDataBlocks
));
if
(
dataBuf
==
NULL
)
{
return
TSDB_CODE_TSC_OUT_OF_MEMORY
;
...
...
@@ -137,8 +137,7 @@ static int32_t createDataBlock(size_t defaultSize, int32_t rowSize, int32_t star
}
memset
(
dataBuf
->
pData
,
0
,
sizeof
(
SSubmitBlk
));
//Here we keep the tableMeta to avoid it to be remove by other threads.
dataBuf
->
pTableMeta
=
tableMetaDup
(
pTableMeta
);
dataBuf
->
pTableMeta
=
pTableMeta
;
SParsedDataColInfo
*
pColInfo
=
&
dataBuf
->
boundColumnInfo
;
SSchema
*
pSchema
=
getTableColumnSchema
(
dataBuf
->
pTableMeta
);
...
...
@@ -176,8 +175,7 @@ int32_t buildCreateTbMsg(STableDataBlocks* pBlocks, SVCreateTbReq* pCreateTbReq)
return
TSDB_CODE_SUCCESS
;
}
int32_t
getDataBlockFromList
(
SHashObj
*
pHashList
,
int64_t
id
,
int32_t
size
,
int32_t
startOffset
,
int32_t
rowSize
,
const
STableMeta
*
pTableMeta
,
STableDataBlocks
**
dataBlocks
,
SArray
*
pBlockList
,
SVCreateTbReq
*
pCreateTbReq
)
{
int32_t
getDataBlockFromList
(
SHashObj
*
pHashList
,
int64_t
id
,
int32_t
size
,
int32_t
startOffset
,
int32_t
rowSize
,
STableMeta
*
pTableMeta
,
STableDataBlocks
**
dataBlocks
,
SArray
*
pBlockList
,
SVCreateTbReq
*
pCreateTbReq
)
{
*
dataBlocks
=
NULL
;
STableDataBlocks
**
t1
=
(
STableDataBlocks
**
)
taosHashGet
(
pHashList
,
(
const
char
*
)
&
id
,
sizeof
(
id
));
if
(
t1
!=
NULL
)
{
...
...
@@ -227,9 +225,9 @@ static void destroyDataBlock(STableDataBlocks* pDataBlock) {
taosMemoryFreeClear
(
pDataBlock
->
pData
);
if
(
!
pDataBlock
->
cloned
)
{
// free the refcount for metermeta
if
(
pDataBlock
->
pTableMeta
!=
NULL
)
{
taosMemoryFreeClear
(
pDataBlock
->
pTableMeta
);
}
//
if (pDataBlock->pTableMeta != NULL) {
//
taosMemoryFreeClear(pDataBlock->pTableMeta);
//
}
destroyBoundColumnInfo
(
&
pDataBlock
->
boundColumnInfo
);
}
...
...
source/libs/parser/src/parUtil.c
浏览文件 @
990205d6
...
...
@@ -166,26 +166,6 @@ int32_t buildSyntaxErrMsg(SMsgBuf* pBuf, const char* additionalInfo, const char*
return
TSDB_CODE_TSC_SQL_SYNTAX_ERROR
;
}
static
uint32_t
getTableMetaSize
(
const
STableMeta
*
pTableMeta
)
{
assert
(
pTableMeta
!=
NULL
);
int32_t
totalCols
=
0
;
if
(
pTableMeta
->
tableInfo
.
numOfColumns
>=
0
)
{
totalCols
=
pTableMeta
->
tableInfo
.
numOfColumns
+
pTableMeta
->
tableInfo
.
numOfTags
;
}
return
sizeof
(
STableMeta
)
+
totalCols
*
sizeof
(
SSchema
);
}
STableMeta
*
tableMetaDup
(
const
STableMeta
*
pTableMeta
)
{
assert
(
pTableMeta
!=
NULL
);
size_t
size
=
getTableMetaSize
(
pTableMeta
);
STableMeta
*
p
=
taosMemoryMalloc
(
size
);
memcpy
(
p
,
pTableMeta
,
size
);
return
p
;
}
SSchema
*
getTableColumnSchema
(
const
STableMeta
*
pTableMeta
)
{
assert
(
pTableMeta
!=
NULL
);
return
(
SSchema
*
)
pTableMeta
->
schema
;
...
...
tools/shell/src/shellCommand.c
浏览文件 @
990205d6
...
...
@@ -51,8 +51,8 @@ void getPrevCharSize(const char *str, int pos, int *size, int *width) {
if
(
str
[
pos
]
>
0
||
countPrefixOnes
((
unsigned
char
)
str
[
pos
])
>
1
)
break
;
}
int
rc
=
taosMbToWchar
(
&
wc
,
str
+
pos
,
MB_CUR_MAX
);
assert
(
rc
==
*
size
);
taosMbToWchar
(
&
wc
,
str
+
pos
,
MB_CUR_MAX
);
// assert(rc == *size); // it will be core, if str is encode by utf8 and taos charset is gbk
*
width
=
taosWcharWidth
(
wc
);
}
...
...
tools/shell/src/shellEngine.c
浏览文件 @
990205d6
...
...
@@ -224,63 +224,27 @@ int32_t shellRunCommand(TAOS *con, char *command) {
}
}
bool
esc
=
false
;
char
quote
=
0
,
*
cmd
=
command
,
*
p
=
command
;
char
quote
=
0
,
*
cmd
=
command
;
for
(
char
c
=
*
command
++
;
c
!=
0
;
c
=
*
command
++
)
{
if
(
esc
)
{
switch
(
c
)
{
case
'n'
:
c
=
'\n'
;
break
;
case
'r'
:
c
=
'\r'
;
break
;
case
't'
:
c
=
'\t'
;
break
;
case
'G'
:
*
p
++
=
'\\'
;
break
;
case
'\''
:
case
'"'
:
if
(
quote
)
{
*
p
++
=
'\\'
;
}
break
;
}
*
p
++
=
c
;
esc
=
false
;
if
(
c
==
'\\'
&&
(
*
command
==
'\''
||
*
command
==
'"'
||
*
command
==
'`'
))
{
command
++
;
continue
;
}
if
(
c
==
'\\'
)
{
if
(
quote
!=
0
&&
(
*
command
==
'_'
||
*
command
==
'\\'
))
{
// DO nothing
}
else
{
esc
=
true
;
continue
;
}
}
if
(
quote
==
c
)
{
quote
=
0
;
}
else
if
(
quote
==
0
&&
(
c
==
'\''
||
c
==
'"'
))
{
}
else
if
(
quote
==
0
&&
(
c
==
'\''
||
c
==
'"'
||
c
==
'`'
))
{
quote
=
c
;
}
*
p
++
=
c
;
if
(
c
==
';'
&&
quote
==
0
)
{
c
=
*
p
;
*
p
=
0
;
}
else
if
(
c
==
';'
&&
quote
==
0
)
{
c
=
*
command
;
*
command
=
0
;
if
(
shellRunSingleCommand
(
con
,
cmd
)
<
0
)
{
return
-
1
;
}
*
p
=
c
;
p
=
cm
d
;
*
command
=
c
;
cmd
=
comman
d
;
}
}
*
p
=
0
;
return
shellRunSingleCommand
(
con
,
cmd
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录