Merge remote-tracking branch 'origin/feature/qnode3' into feature/qnode
This commit is contained in:
commit
362440660f
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef TDENGINE_CLIENTSTMT_H
|
||||
#define TDENGINE_CLIENTSTMT_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef enum {
|
||||
STMT_TYPE_INSERT = 1,
|
||||
STMT_TYPE_MULTI_INSERT,
|
||||
STMT_TYPE_QUERY,
|
||||
} STMT_TYPE;
|
||||
|
||||
typedef struct STscStmt {
|
||||
STMT_TYPE type;
|
||||
int16_t last;
|
||||
STscObj* taos;
|
||||
SSqlObj* pSql;
|
||||
SMultiTbStmt mtb;
|
||||
SNormalStmt normal;
|
||||
|
||||
int numOfRows;
|
||||
} STscStmt;
|
||||
|
||||
#define SCH_ERR_RET(c) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { terrno = _code; return _code; } } while (0)
|
||||
#define SCH_RET(c) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { terrno = _code; } return _code; } while (0)
|
||||
#define SCH_ERR_JRET(c) do { code = c; if (code != TSDB_CODE_SUCCESS) { terrno = code; goto _return; } } while (0)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // TDENGINE_CLIENTSTMT_H
|
|
@ -559,76 +559,149 @@ int taos_load_table_info(TAOS *taos, const char *tableNameList) {
|
|||
}
|
||||
|
||||
TAOS_STMT *taos_stmt_init(TAOS *taos) {
|
||||
// TODO
|
||||
return NULL;
|
||||
if (taos == NULL) {
|
||||
tscError("NULL parameter for %s", __FUNC__);
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return stmtInit(taos);
|
||||
}
|
||||
|
||||
int taos_stmt_close(TAOS_STMT *stmt) {
|
||||
// TODO
|
||||
return -1;
|
||||
if (stmt == NULL) {
|
||||
tscError("NULL parameter for %s", __FUNC__);
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return terrno;
|
||||
}
|
||||
|
||||
return stmtClose(stmt);
|
||||
}
|
||||
|
||||
int taos_stmt_execute(TAOS_STMT *stmt) {
|
||||
// TODO
|
||||
return -1;
|
||||
if (stmt == NULL) {
|
||||
tscError("NULL parameter for %s", __FUNC__);
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return terrno;
|
||||
}
|
||||
|
||||
return stmtExec(stmt);
|
||||
}
|
||||
|
||||
char *taos_stmt_errstr(TAOS_STMT *stmt) {
|
||||
// TODO
|
||||
return NULL;
|
||||
if (stmt == NULL) {
|
||||
tscError("NULL parameter for %s", __FUNC__);
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return stmtErrstr(stmt);
|
||||
}
|
||||
|
||||
int taos_stmt_affected_rows(TAOS_STMT *stmt) {
|
||||
// TODO
|
||||
return -1;
|
||||
if (stmt == NULL) {
|
||||
tscError("NULL parameter for %s", __FUNC__);
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return stmtAffectedRows(stmt);
|
||||
}
|
||||
|
||||
int taos_stmt_bind_param(TAOS_STMT *stmt, TAOS_BIND *bind) {
|
||||
if (stmt == NULL || bind == NULL) {
|
||||
tscError("NULL parameter for %s", __FUNC__);
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return terrno;
|
||||
}
|
||||
|
||||
return stmtBind(stmt, bind);
|
||||
}
|
||||
|
||||
int taos_stmt_prepare(TAOS_STMT *stmt, const char *sql, unsigned long length) {
|
||||
if (stmt == NULL || sql == NULL) {
|
||||
tscError("NULL parameter for %s", __FUNC__);
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return terrno;
|
||||
}
|
||||
|
||||
return stmtPrepare(stmt, sql, length);
|
||||
}
|
||||
|
||||
int taos_stmt_set_tbname_tags(TAOS_STMT *stmt, const char *name, TAOS_BIND *tags) {
|
||||
if (stmt == NULL || name == NULL || tags == NULL) {
|
||||
tscError("NULL parameter for %s", __FUNC__);
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return terrno;
|
||||
}
|
||||
|
||||
return stmtSetTbNameTags(stmt, name, tags);
|
||||
}
|
||||
|
||||
int taos_stmt_set_tbname(TAOS_STMT *stmt, const char *name) {
|
||||
if (stmt == NULL || name == NULL) {
|
||||
tscError("NULL parameter for %s", __FUNC__);
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return terrno;
|
||||
}
|
||||
|
||||
return stmtSetTbNameTags(stmt, name, NULL);
|
||||
}
|
||||
|
||||
int taos_stmt_is_insert(TAOS_STMT *stmt, int *insert) {
|
||||
if (stmt == NULL || insert == NULL) {
|
||||
tscError("NULL parameter for %s", __FUNC__);
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return terrno;
|
||||
}
|
||||
|
||||
return stmtIsInsert(stmt, insert);
|
||||
}
|
||||
|
||||
int taos_stmt_num_params(TAOS_STMT *stmt, int *nums) {
|
||||
if (stmt == NULL || nums == NULL) {
|
||||
tscError("NULL parameter for %s", __FUNC__);
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return terrno;
|
||||
}
|
||||
|
||||
return stmtGetParamNum(stmt, nums);
|
||||
}
|
||||
|
||||
int taos_stmt_add_batch(TAOS_STMT *stmt) {
|
||||
if (stmt == NULL) {
|
||||
tscError("NULL parameter for %s", __FUNC__);
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return terrno;
|
||||
}
|
||||
|
||||
return stmtAddBatch(stmt);
|
||||
}
|
||||
|
||||
TAOS_RES *taos_stmt_use_result(TAOS_STMT *stmt) {
|
||||
if (stmt == NULL) {
|
||||
tscError("NULL parameter for %s", __FUNC__);
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return terrno;
|
||||
}
|
||||
|
||||
return stmtUseResult(stmt);
|
||||
}
|
||||
|
||||
int taos_stmt_bind_param_batch(TAOS_STMT *stmt, TAOS_MULTI_BIND *bind) {
|
||||
if (stmt == NULL || bind == NULL) {
|
||||
tscError("NULL parameter for %s", __FUNC__);
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return terrno;
|
||||
}
|
||||
|
||||
return stmtBindBatch(stmt, bind);
|
||||
}
|
||||
|
||||
|
||||
TAOS_RES *taos_schemaless_insert(TAOS *taos, char *lines[], int numLines, int protocol, int precision) {
|
||||
// TODO
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int taos_stmt_bind_param(TAOS_STMT *stmt, TAOS_BIND *bind) {
|
||||
// TODO
|
||||
return -1;
|
||||
}
|
||||
|
||||
int taos_stmt_prepare(TAOS_STMT *stmt, const char *sql, unsigned long length) {
|
||||
// TODO
|
||||
return -1;
|
||||
}
|
||||
|
||||
int taos_stmt_set_tbname_tags(TAOS_STMT *stmt, const char *name, TAOS_BIND *tags) {
|
||||
// TODO
|
||||
return -1;
|
||||
}
|
||||
|
||||
int taos_stmt_set_tbname(TAOS_STMT *stmt, const char *name) {
|
||||
// TODO
|
||||
return -1;
|
||||
}
|
||||
|
||||
int taos_stmt_is_insert(TAOS_STMT *stmt, int *insert) {
|
||||
// TODO
|
||||
return -1;
|
||||
}
|
||||
|
||||
int taos_stmt_num_params(TAOS_STMT *stmt, int *nums) {
|
||||
// TODO
|
||||
return -1;
|
||||
}
|
||||
|
||||
int taos_stmt_add_batch(TAOS_STMT *stmt) {
|
||||
// TODO
|
||||
return -1;
|
||||
}
|
||||
|
||||
TAOS_RES *taos_stmt_use_result(TAOS_STMT *stmt) {
|
||||
// TODO
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int taos_stmt_bind_param_batch(TAOS_STMT *stmt, TAOS_MULTI_BIND *bind) {
|
||||
// TODO
|
||||
return -1;
|
||||
}
|
||||
|
|
|
@ -46,4 +46,3 @@ TAOS_STMT *stmtInit(TAOS *taos) {
|
|||
return pStmt;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -223,11 +223,15 @@ static int32_t createSName(SName* pName, SToken* pTableName, SParseContext* pPar
|
|||
return code;
|
||||
}
|
||||
|
||||
static int32_t getTableMeta(SInsertParseContext* pCxt, SToken* pTname) {
|
||||
static int32_t getTableMetaImpl(SInsertParseContext* pCxt, SToken* pTname, bool isStb) {
|
||||
SParseContext* pBasicCtx = pCxt->pComCxt;
|
||||
SName name = {0};
|
||||
createSName(&name, pTname, pBasicCtx, &pCxt->msg);
|
||||
CHECK_CODE(catalogGetTableMeta(pBasicCtx->pCatalog, pBasicCtx->pTransporter, &pBasicCtx->mgmtEpSet, &name, &pCxt->pTableMeta));
|
||||
if (isStb) {
|
||||
CHECK_CODE(catalogGetSTableMeta(pBasicCtx->pCatalog, pBasicCtx->pTransporter, &pBasicCtx->mgmtEpSet, &name, &pCxt->pTableMeta));
|
||||
} else {
|
||||
CHECK_CODE(catalogGetTableMeta(pBasicCtx->pCatalog, pBasicCtx->pTransporter, &pBasicCtx->mgmtEpSet, &name, &pCxt->pTableMeta));
|
||||
}
|
||||
SVgroupInfo vg;
|
||||
CHECK_CODE(catalogGetTableHashVgroup(pBasicCtx->pCatalog, pBasicCtx->pTransporter, &pBasicCtx->mgmtEpSet, &name, &vg));
|
||||
CHECK_CODE(taosHashPut(pCxt->pVgroupsHashObj, (const char*)&vg.vgId, sizeof(vg.vgId), (char*)&vg, sizeof(vg)));
|
||||
|
@ -235,6 +239,15 @@ static int32_t getTableMeta(SInsertParseContext* pCxt, SToken* pTname) {
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t getTableMeta(SInsertParseContext* pCxt, SToken* pTname) {
|
||||
return getTableMetaImpl(pCxt, pTname, false);
|
||||
}
|
||||
|
||||
static int32_t getSTableMeta(SInsertParseContext* pCxt, SToken* pTname) {
|
||||
return getTableMetaImpl(pCxt, pTname, true);
|
||||
}
|
||||
|
||||
|
||||
static int32_t findCol(SToken* pColname, int32_t start, int32_t end, SSchema* pSchema) {
|
||||
while (start < end) {
|
||||
if (strlen(pSchema[start].name) == pColname->n && strncmp(pColname->z, pSchema[start].name, pColname->n) == 0) {
|
||||
|
@ -811,7 +824,7 @@ static int32_t parseUsingClause(SInsertParseContext* pCxt, SToken* pTbnameToken)
|
|||
SToken sToken;
|
||||
// pSql -> stb_name [(tag1_name, ...)] TAGS (tag1_value, ...)
|
||||
NEXT_TOKEN(pCxt->pSql, sToken);
|
||||
CHECK_CODE(getTableMeta(pCxt, &sToken));
|
||||
CHECK_CODE(getSTableMeta(pCxt, &sToken));
|
||||
if (TSDB_SUPER_TABLE != pCxt->pTableMeta->tableType) {
|
||||
return buildInvalidOperationMsg(&pCxt->msg, "create table only from super table is allowed");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue