diff --git a/src/dnode/src/dnodeWrite.c b/src/dnode/src/dnodeWrite.c index e09d184efa3c60fdda68ee84ac54a336c8c71b81..1b6c6c148f234daf4db713b199b4a1d22a68ed08 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 60407b028ff98bb5f1cff9247ace6f729abcd480..a08775684bc3361a8298a1e335dbc93d785350c8 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 c747219adb8059f2bac098f66894c19da29a1b52..ec286091e16eb3e4af40dc4d64206ba0f8de71b7 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) {