stmt2 support insert into stb(?)values(tbname)
This commit is contained in:
parent
fb8a10e717
commit
ede70d0465
|
@ -194,6 +194,7 @@ typedef struct SBoundColInfo {
|
||||||
int32_t numOfCols;
|
int32_t numOfCols;
|
||||||
int32_t numOfBound;
|
int32_t numOfBound;
|
||||||
bool hasBoundCols;
|
bool hasBoundCols;
|
||||||
|
bool mixTagsCols;
|
||||||
} SBoundColInfo;
|
} SBoundColInfo;
|
||||||
|
|
||||||
typedef struct STableColsData {
|
typedef struct STableColsData {
|
||||||
|
|
|
@ -247,8 +247,8 @@ static int32_t parseBoundColumns(SInsertParseContext* pCxt, const char** pSql, E
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t parseTimestampOrInterval(const char** end, SToken* pToken, int16_t timePrec, int64_t* ts, int64_t* interval,
|
static int32_t parseTimestampOrInterval(const char** end, SToken* pToken, int16_t timePrec, int64_t* ts,
|
||||||
SMsgBuf* pMsgBuf, bool* isTs) {
|
int64_t* interval, SMsgBuf* pMsgBuf, bool* isTs) {
|
||||||
if (pToken->type == TK_NOW) {
|
if (pToken->type == TK_NOW) {
|
||||||
*isTs = true;
|
*isTs = true;
|
||||||
*ts = taosGetTimestamp(timePrec);
|
*ts = taosGetTimestamp(timePrec);
|
||||||
|
@ -1831,13 +1831,26 @@ static int32_t doGetStbRowValues(SInsertParseContext* pCxt, SVnodeModifyOpStmt*
|
||||||
|
|
||||||
if (TK_NK_QUESTION == pToken->type) {
|
if (TK_NK_QUESTION == pToken->type) {
|
||||||
pCxt->isStmtBind = true;
|
pCxt->isStmtBind = true;
|
||||||
|
pStmt->usingTableProcessing = true;
|
||||||
if (pCols->pColIndex[i] == tbnameIdx) {
|
if (pCols->pColIndex[i] == tbnameIdx) {
|
||||||
pCxt->preCtbname = false;
|
char* tbName = NULL;
|
||||||
|
if ((*pCxt->pComCxt->pStmtCb->getTbNameFn)(pCxt->pComCxt->pStmtCb->pStmt, &tbName) == TSDB_CODE_SUCCESS) {
|
||||||
|
tstrncpy(pStbRowsCxt->ctbName.tname, tbName, sizeof(pStbRowsCxt->ctbName.tname));
|
||||||
|
tstrncpy(pStmt->usingTableName.tname, pStmt->targetTableName.tname, sizeof(pStmt->usingTableName.tname));
|
||||||
|
tstrncpy(pStmt->targetTableName.tname, tbName, sizeof(pStmt->targetTableName.tname));
|
||||||
|
|
||||||
|
tstrncpy(pStmt->usingTableName.dbname, pStmt->targetTableName.dbname, sizeof(pStmt->usingTableName.dbname));
|
||||||
|
pStmt->usingTableName.type = 1;
|
||||||
|
|
||||||
*bFoundTbName = true;
|
*bFoundTbName = true;
|
||||||
}
|
}
|
||||||
if (NULL == pCxt->pComCxt->pStmtCb) {
|
} else if (pCols->pColIndex[i] < numOfCols) {
|
||||||
code = buildSyntaxErrMsg(&pCxt->msg, "? only used in stmt", pToken->z);
|
// bind column
|
||||||
break;
|
} else {
|
||||||
|
pCxt->tags.mixTagsCols = true;
|
||||||
|
pCxt->tags.pColIndex = pStbRowsCxt->boundColsInfo.pColIndex;
|
||||||
|
pCxt->tags.numOfBound++;
|
||||||
|
pCxt->tags.numOfCols++;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (pCols->pColIndex[i] < numOfCols) {
|
if (pCols->pColIndex[i] < numOfCols) {
|
||||||
|
@ -1901,14 +1914,18 @@ static int32_t getStbRowValues(SInsertParseContext* pCxt, SVnodeModifyOpStmt* pS
|
||||||
code = doGetStbRowValues(pCxt, pStmt, ppSql, pStbRowsCxt, pToken, pCols, pSchemas, tagTokens, tagSchemas,
|
code = doGetStbRowValues(pCxt, pStmt, ppSql, pStbRowsCxt, pToken, pCols, pSchemas, tagTokens, tagSchemas,
|
||||||
&numOfTagTokens, &bFoundTbName);
|
&numOfTagTokens, &bFoundTbName);
|
||||||
|
|
||||||
if (code == TSDB_CODE_SUCCESS && !bFoundTbName) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
code = buildSyntaxErrMsg(&pCxt->msg, "tbname value expected", pOrigSql);
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (code == TSDB_CODE_SUCCESS && pStbRowsCxt->ctbName.tname[0] == '\0') {
|
if (!bFoundTbName) {
|
||||||
|
if (!pCxt->isStmtBind) {
|
||||||
|
code = buildSyntaxErrMsg(&pCxt->msg, "tbname value expected", pOrigSql);
|
||||||
|
} else {
|
||||||
*pGotRow = true;
|
*pGotRow = true;
|
||||||
return TSDB_CODE_TSC_STMT_TBNAME_ERROR;
|
return TSDB_CODE_TSC_STMT_TBNAME_ERROR;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool ctbFirst = true;
|
bool ctbFirst = true;
|
||||||
char ctbFName[TSDB_TABLE_FNAME_LEN];
|
char ctbFName[TSDB_TABLE_FNAME_LEN];
|
||||||
|
@ -2050,14 +2067,24 @@ static int32_t parseOneStbRow(SInsertParseContext* pCxt, SVnodeModifyOpStmt* pSt
|
||||||
code = processCtbAutoCreationAndCtbMeta(pCxt, pStmt, pStbRowsCxt);
|
code = processCtbAutoCreationAndCtbMeta(pCxt, pStmt, pStbRowsCxt);
|
||||||
}
|
}
|
||||||
if (code == TSDB_CODE_SUCCESS) {
|
if (code == TSDB_CODE_SUCCESS) {
|
||||||
|
if (pCxt->isStmtBind) {
|
||||||
|
char ctbFName[TSDB_TABLE_FNAME_LEN];
|
||||||
|
code = tNameExtractFullName(&pStbRowsCxt->ctbName, ctbFName);
|
||||||
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
code = insGetTableDataCxt(pStmt->pTableBlockHashObj, ctbFName, strlen(ctbFName), pStbRowsCxt->pCtbMeta,
|
||||||
|
&pStbRowsCxt->pCreateCtbReq, ppTableDataCxt, true, true);
|
||||||
|
} else {
|
||||||
code =
|
code =
|
||||||
insGetTableDataCxt(pStmt->pTableBlockHashObj, &pStbRowsCxt->pCtbMeta->uid, sizeof(pStbRowsCxt->pCtbMeta->uid),
|
insGetTableDataCxt(pStmt->pTableBlockHashObj, &pStbRowsCxt->pCtbMeta->uid, sizeof(pStbRowsCxt->pCtbMeta->uid),
|
||||||
pStbRowsCxt->pCtbMeta, &pStbRowsCxt->pCreateCtbReq, ppTableDataCxt, false, true);
|
pStbRowsCxt->pCtbMeta, &pStbRowsCxt->pCreateCtbReq, ppTableDataCxt, false, true);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (code == TSDB_CODE_SUCCESS) {
|
if (code == TSDB_CODE_SUCCESS) {
|
||||||
code = initTableColSubmitData(*ppTableDataCxt);
|
code = initTableColSubmitData(*ppTableDataCxt);
|
||||||
}
|
}
|
||||||
if (code == TSDB_CODE_SUCCESS) {
|
if (code == TSDB_CODE_SUCCESS && !pCxt->isStmtBind) {
|
||||||
SRow** pRow = taosArrayReserve((*ppTableDataCxt)->pData->aRowP, 1);
|
SRow** pRow = taosArrayReserve((*ppTableDataCxt)->pData->aRowP, 1);
|
||||||
code = tRowBuild(pStbRowsCxt->aColVals, (*ppTableDataCxt)->pSchema, pRow);
|
code = tRowBuild(pStbRowsCxt->aColVals, (*ppTableDataCxt)->pSchema, pRow);
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
|
|
@ -503,7 +503,12 @@ int32_t qBindStmtTagsValue2(void* pBlock, void* boundTags, int64_t suid, const c
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
SSchema* pSchema = getTableTagSchema(pDataBlock->pMeta);
|
SSchema* pSchema;
|
||||||
|
if (!tags->mixTagsCols) {
|
||||||
|
pSchema = getTableTagSchema(pDataBlock->pMeta);
|
||||||
|
} else {
|
||||||
|
pSchema = getTableColumnSchema(pDataBlock->pMeta);
|
||||||
|
}
|
||||||
|
|
||||||
bool isJson = false;
|
bool isJson = false;
|
||||||
STag* pTag = NULL;
|
STag* pTag = NULL;
|
||||||
|
@ -958,16 +963,16 @@ int32_t buildStbBoundFields(SBoundColInfo boundColsInfo, SSchema* pSchema, int32
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tags->numOfBound > 0) {
|
if (tags->numOfBound > 0) {
|
||||||
SSchema* pSchema = getTableTagSchema(pMeta);
|
SSchema* tagSchema = getTableTagSchema(pMeta);
|
||||||
|
|
||||||
if (TSDB_DATA_TYPE_TIMESTAMP == pSchema->type) {
|
if (TSDB_DATA_TYPE_TIMESTAMP == tagSchema->type) {
|
||||||
(*fields)[0].precision = pMeta->tableInfo.precision;
|
(*fields)[0].precision = pMeta->tableInfo.precision;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int32_t i = 0; i < tags->numOfBound; ++i) {
|
for (int32_t i = 0; i < tags->numOfBound; ++i) {
|
||||||
(*fields)[idx].field_type = TAOS_FIELD_TAG;
|
(*fields)[idx].field_type = TAOS_FIELD_TAG;
|
||||||
|
|
||||||
SSchema* schema = &pSchema[tags->pColIndex[i]];
|
SSchema* schema = &tagSchema[tags->pColIndex[i]];
|
||||||
tstrncpy((*fields)[idx].name, schema->name, sizeof((*fields)[i].name));
|
tstrncpy((*fields)[idx].name, schema->name, sizeof((*fields)[i].name));
|
||||||
(*fields)[idx].type = schema->type;
|
(*fields)[idx].type = schema->type;
|
||||||
(*fields)[idx].bytes = schema->bytes;
|
(*fields)[idx].bytes = schema->bytes;
|
||||||
|
|
|
@ -191,6 +191,7 @@ int32_t insInitBoundColsInfo(int32_t numOfBound, SBoundColInfo* pInfo) {
|
||||||
pInfo->numOfCols = numOfBound;
|
pInfo->numOfCols = numOfBound;
|
||||||
pInfo->numOfBound = numOfBound;
|
pInfo->numOfBound = numOfBound;
|
||||||
pInfo->hasBoundCols = false;
|
pInfo->hasBoundCols = false;
|
||||||
|
pInfo->mixTagsCols = false;
|
||||||
pInfo->pColIndex = taosMemoryCalloc(numOfBound, sizeof(int16_t));
|
pInfo->pColIndex = taosMemoryCalloc(numOfBound, sizeof(int16_t));
|
||||||
if (NULL == pInfo->pColIndex) {
|
if (NULL == pInfo->pColIndex) {
|
||||||
return terrno;
|
return terrno;
|
||||||
|
@ -204,6 +205,7 @@ int32_t insInitBoundColsInfo(int32_t numOfBound, SBoundColInfo* pInfo) {
|
||||||
void insResetBoundColsInfo(SBoundColInfo* pInfo) {
|
void insResetBoundColsInfo(SBoundColInfo* pInfo) {
|
||||||
pInfo->numOfBound = pInfo->numOfCols;
|
pInfo->numOfBound = pInfo->numOfCols;
|
||||||
pInfo->hasBoundCols = false;
|
pInfo->hasBoundCols = false;
|
||||||
|
pInfo->mixTagsCols = false;
|
||||||
for (int32_t i = 0; i < pInfo->numOfCols; ++i) {
|
for (int32_t i = 0; i < pInfo->numOfCols; ++i) {
|
||||||
pInfo->pColIndex[i] = i;
|
pInfo->pColIndex[i] = i;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue