From d7e96770f119b5f65f915921ef1ef01730830293 Mon Sep 17 00:00:00 2001 From: slguan Date: Sun, 15 Mar 2020 01:03:03 +0800 Subject: [PATCH] [TD-10] pass tag values --- src/dnode/src/dnodeWrite.c | 25 +++++++++++++++++++------ src/mnode/src/mgmtNormalTable.c | 3 ++- src/mnode/src/mgmtSuperTable.c | 3 ++- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/dnode/src/dnodeWrite.c b/src/dnode/src/dnodeWrite.c index e09d184efa..1b6c6c148f 100644 --- a/src/dnode/src/dnodeWrite.c +++ b/src/dnode/src/dnodeWrite.c @@ -322,25 +322,38 @@ static void dnodeProcessCreateTableMsg(SWriteMsg *pMsg) { pTable->createdTime = htobe64(pTable->createdTime); SSchema *pSchema = (SSchema *) pTable->data; + int totalCols = pTable->numOfColumns + pTable->numOfTags; + for (int i = 0; i < totalCols; i++) { + pSchema[i].colId = htons(pSchema[i].colId); + pSchema[i].bytes = htons(pSchema[i].bytes); + } + STableCfg tCfg; tsdbInitTableCfg(&tCfg, pTable->tableType, pTable->uid, pTable->sid); STSchema *pDestSchema = tdNewSchema(pTable->numOfColumns); for (int i = 0; i < pTable->numOfColumns; i++) { - tdSchemaAppendCol(pDestSchema, pSchema[i].type, htons(pSchema[i].colId), htons(pSchema[i].bytes)); + tdSchemaAppendCol(pDestSchema, pSchema[i].type, pSchema[i].colId, pSchema[i].bytes); } tsdbTableSetSchema(&tCfg, pDestSchema, false); - if (pTable->numOfTags != NULL) { + if (pTable->numOfTags != 0) { STSchema *pDestTagSchema = tdNewSchema(pTable->numOfTags); - for (int i = pTable->numOfColumns; i < pTable->numOfColumns + pTable->numOfTags; i++) { - tdSchemaAppendCol(pDestTagSchema, pSchema[i].type, htons(pSchema[i].colId), htons(pSchema[i].bytes)); + for (int i = pTable->numOfColumns; i < totalCols; i++) { + tdSchemaAppendCol(pDestTagSchema, pSchema[i].type, pSchema[i].colId, pSchema[i].bytes); } tsdbTableSetSchema(&tCfg, pDestTagSchema, false); - } - if (pTable->tableType == TSDB_CHILD_TABLE) { // TODO: add data row + char *pTagData = pTable->data + totalCols * sizeof(SSchema); + int accumBytes = 0; + SDataRow dataRow = tdNewDataRowFromSchema(pDestTagSchema); + + for (int i = 0; i < pTable->numOfTags; i++) { + tdAppendColVal(dataRow, pTagData + accumBytes, pDestTagSchema->columns + i); + accumBytes += pSchema[i + pTable->numOfColumns].bytes; + } + tsdbTableSetTagValue(&tCfg, dataRow, false); } rpcRsp.code = tsdbCreateTable(pTsdb, &tCfg); diff --git a/src/mnode/src/mgmtNormalTable.c b/src/mnode/src/mgmtNormalTable.c index 60407b028f..a08775684b 100644 --- a/src/mnode/src/mgmtNormalTable.c +++ b/src/mnode/src/mgmtNormalTable.c @@ -358,8 +358,9 @@ int32_t mgmtCreateNormalTable(SCMCreateTableMsg *pCreate, int32_t contLen, SVgOb pTable->nextColId = 0; for (int32_t col = 0; col < pCreate->numOfColumns; col++) { - SSchema *tschema = (SSchema *) pTable->schema; + SSchema *tschema = pTable->schema; tschema[col].colId = pTable->nextColId++; + tschema[col].bytes = pTable->schema[col].bytes; } pTable->sqlLen = pCreate->sqlLen; diff --git a/src/mnode/src/mgmtSuperTable.c b/src/mnode/src/mgmtSuperTable.c index c747219adb..ec286091e1 100644 --- a/src/mnode/src/mgmtSuperTable.c +++ b/src/mnode/src/mgmtSuperTable.c @@ -235,9 +235,10 @@ int32_t mgmtCreateSuperTable(SDbObj *pDb, SCMCreateTableMsg *pCreate) { memcpy(pStable->schema, pCreate->schema, numOfCols * sizeof(SSchema)); pStable->nextColId = 0; - for (int32_t col = 0; col < pStable->numOfColumns; col++) { + for (int32_t col = 0; col < numOfCols; col++) { SSchema *tschema = pStable->schema; tschema[col].colId = pStable->nextColId++; + tschema[col].bytes = htons(tschema[col].bytes); } if (sdbInsertRow(tsSuperTableSdb, pStable, 0) < 0) { -- GitLab